我试图绘制数据。首先,我从文件加载数据
data = load('ex1data1.txt'); % read comma separated data
X = data(:, 1); y = data(:, 2);
m = length(y); % number of training examples
然后我调用了函数plotData
function figure=plotData(x, y)
figure; % open a new figure window
if(is_vector(x) && is_vector(y))
figure=plot(x,y,'rx',MarkerSize,10);
xlabel('Profit in $10,000s');
ylabel('Population of city in 10,000s');
endif
endfunction
但是我犯了一个错误。上面写着:x未定义提前感谢。
问题出现在以下语句中:
X = data(:, 1); y = data(:, 2);
您已经定义了X
变量,但当您调用时
plotData(x, y)
您使用的是小写的X
我认为如果改变声明:plotData(X, y)
将解决您的问题