Sasirekha MSVL
Sasirekha MSVL

Reputation: 63

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.

Upvotes: 0

Views: 1056

Answers (1)

Ahx
Ahx

Reputation: 7995

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

Upvotes: 2

Related Questions