0

While executing the plotdata file in octave I'm getting the following error:

plotData error: 'x' undefined near line 7 column 6 error: called from plotData at line 7 column 1 plotData error: 'y' undefined near line 7 column 6 error: called from plotData at line 7 column 1

My code:

function plotData(x, y)

figure;

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

ylabel('Profit in $10,000s');

xlabel('Population of city in 10,000s');

end
melpomene
  • 84,125
  • 8
  • 85
  • 148
  • Please add a complete piece oft code. See MCVE. Your call to plotData misses x and y – Andy Sep 28 '19 at 04:03
  • Possible duplicate of [Octave GNU: Undefined variable 'x' , even though it's defined as function input](https://stackoverflow.com/questions/44508581/octave-gnu-undefined-variable-x-even-though-its-defined-as-function-input) – Cris Luengo Sep 28 '19 at 17:02

1 Answers1

0

plotData expects a x and y value to be provided when running.

if you press the run button on the GUI you aren't giving it an e, y value.

Likewise if you run as 'plotData' in the console window, you aren't giving an x,y value

In both cases, no x,y value means that x and y variables have not been defined in the function and so the error occurs.

If you ran as:

plotData(10,20)

You would not have the error occur as a x,y value is being provided.

lostbard
  • 5,065
  • 1
  • 15
  • 17