简体   繁体   English

MATLAB 绘图函数没有足够的输入参数

[英]MATLAB plotting function not enough input arguments

I am currently taking Andrew Ng's Stanford Machine learning course and am using MATLAB to complete the programming assignments despite being new to the MATLAB programming language as the course requires completion of assignments in either Ocatave or MATLAB.我目前正在参加 Andrew Ng 的斯坦福机器学习课程,尽管我是 MATLAB 编程语言的新手,但我正在使用 MATLAB 完成编程作业,因为该课程需要在 Ocatave 或 MATLAB 中完成作业。 For the first programming assignment the course offers Octave/MATLAB script that steps you through the exercises.对于第一个编程作业,本课程提供 Octave/MATLAB 脚本,引导您完成练习。 I am attempting to write a MATLAB function that will plot data for x and y variables, however, am continuing to run into the same error and am beginning to spin my wheels with finding a solution.我正在尝试编写一个 MATLAB 函数来绘制 x 和 y 变量的数据,但是,我继续遇到相同的错误,并开始寻找解决方案。 I have a plotData.m file I am working off of and here is the code I have put together:我有一个正在处理的 plotData.m 文件,这是我放在一起的代码:

function plotData(x, y)
%PLOTDATA Plots the data points x and y into a new figure 
%   PLOTDATA(x,y) plots the data points and gives the figure axes labels of
%   population and profit.

figure; % open a new figure window
hold on;

% ====================== YOUR CODE HERE ======================
% Instructions: Plot the training data into a figure using the 
%               "figure" and "plot" commands. Set the axes labels using
%               the "xlabel" and "ylabel" commands. Assume the 
%               population and revenue data have been passed in
%               as the x and y arguments of this function.
%
% Hint: You can use the 'rx' option with plot to have the markers
%       appear as red crosses. Furthermore, you can make the
%       markers larger by using plot(..., 'rx', 'MarkerSize', 10);

plot(x, y, 'rx');
xlabel('population (in tens of thousands)');
ylabel('profit (in $10,000s)');

hold off;

% ============================================================

end

Every time I run this script I receive an error stating 'Not enough input arguments.每次运行此脚本时,我都会收到一条错误消息,指出“输入参数不足。 Error in plotData (line 19) plot(x, y, 'rx');'. plotData 错误(第 19 行)plot(x, y, 'rx');'。 This is a fairly ambiguous error message and I am not sure how to interpret what is wrong here.这是一个相当含糊的错误消息,我不确定如何解释这里的错误。 I don't see why I wouldn't have enough input arguments in this example as the function explicitly takes both x and y and uses each to plot data as defined by the function.我不明白为什么在这个例子中我没有足够的输入参数,因为函数显式地接受 x 和 y 并使用每个来绘制函数定义的数据。 Any help would be greatly appreciated.任何帮助将不胜感激。

I am using MATLAB version 9.6.0.1114505 (R2019a) Update 2我正在使用 MATLAB 版本 9.6.0.1114505 (R2019a) 更新 2

我在运行“plotData.m”时遇到同样的错误,请尝试运行“ex1.m”而不是“plotData.m”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM