繁体   English   中英

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

[英]MATLAB plotting function not enough input arguments

我目前正在参加 Andrew Ng 的斯坦福机器学习课程,尽管我是 MATLAB 编程语言的新手,但我正在使用 MATLAB 完成编程作业,因为该课程需要在 Ocatave 或 MATLAB 中完成作业。 对于第一个编程作业,本课程提供 Octave/MATLAB 脚本,引导您完成练习。 我正在尝试编写一个 MATLAB 函数来绘制 x 和 y 变量的数据,但是,我继续遇到相同的错误,并开始寻找解决方案。 我有一个正在处理的 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

每次运行此脚本时,我都会收到一条错误消息,指出“输入参数不足。 plotData 错误(第 19 行)plot(x, y, 'rx');'。 这是一个相当含糊的错误消息,我不确定如何解释这里的错误。 我不明白为什么在这个例子中我没有足够的输入参数,因为函数显式地接受 x 和 y 并使用每个来绘制函数定义的数据。 任何帮助将不胜感激。

我正在使用 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