简体   繁体   中英

How to solve the Error: x undefined in octave

I was trying to plot data. 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 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.

The problem is in the following statement:

X = data(:, 1); y = data(:, 2);

you have defined X variable but when you call

plotData(x, y)

you are using lowercase X

I think if change the statement: plotData(X, y) will solve your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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