为什么我能';运行此matlab代码后是否查看绘图?

为什么我能';运行此matlab代码后是否查看绘图?,matlab,Matlab,以下是函数plotData的matlab代码: fprintf('Plotting Data ...\n') data = load('ex1data1.txt'); x = data(:, 1); y = data(:, 2); m = length(y); % number of training examples % Plot Data % Note: You have to complete the code in plotData.m plotData(x, y); fprintf(

以下是函数plotData的matlab代码:

fprintf('Plotting Data ...\n')
data = load('ex1data1.txt');
x = data(:, 1); y = data(:, 2);
m = length(y); % number of training examples

% Plot Data
% Note: You have to complete the code in plotData.m
plotData(x, y);
fprintf('Program paused. Press enter to continue.\n');
pause;
运行上述代码后,会出现以下错误:

plotData(第16行)中的错误plotData(x,y,'rx','MarkerSize',10)

ex1(第49行)绘图数据(x,y)中出错


您正在函数
plotData
中调用函数
plotData
,这在这里没有意义

您需要调用
plot
,如下所示:

function plotData(x, y)
  plotData (x,y,'rx', 'MarkerSize', 10);
  ylabel ('Profit in $10,000s');
  xlabel('Population of city in 10,000');
  figure;
end
函数内部

因此,将
plotData
更改为:

plot(x,y,'rx', 'MarkerSize', 10);

请注意,在实际生成绘图之前,我添加了对
figure
的调用,这对我来说更有意义。

您需要使用
plot
先生,我是否应该使用我在代码的第一块中提到的主代码体中的plot或plotData。我已经更正了您告诉我的错误,但它仍然显示相同的错误。在第一个块中,您可以使用
plotData
调用函数。你能显示整个错误信息吗?代码现在运行正常。谢谢,先生。但是我想知道plot()的代码行在我的代码中做了什么。我知道我们一开始定义了函数plotData(x,y),但是接下来我们在包含plot()的代码行中所做的工作非常好,欢迎您。该行以您指定的颜色和行样式显示变量
x
y
中包含的数据。查看更多详细信息。在您的例子中,您告诉Matlab将红色十字标绘为符号(即,
rx
),大小为10。
function plotData(x, y)

figure %// Note that figure is called before the plot
plot(x,y,'rx', 'MarkerSize', 10);
ylabel ('Profit in $10,000s');
xlabel('Population of city in 10,000');

end