[英]How to solve the Error: x undefined in octave
I was trying to plot data.我正在尝试 plot 数据。 Firstly, I have load the data from a file
首先,我从文件中加载数据
data = load('ex1data1.txt'); % read comma separated data
X = data(:, 1); y = data(:, 2);
m = length(y); % number of training examples
Then i have called the function plotData然后我调用了 function 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
But Iam getting an error.但我收到一个错误。 which says: x is undefined Thank you in advance.
其中说: x 未定义提前谢谢你。
The problem is in the following statement:问题出在以下语句中:
X = data(:, 1); y = data(:, 2);
you have defined X
variable but when you call你已经定义了
X
变量但是当你调用
plotData(x, y)
you are using lowercase X你正在使用小写 X
I think if change the statement: plotData(X, y)
will solve your problem我认为如果更改语句:
plotData(X, y)
将解决您的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.