Scatter works but Plot gives error

3 views (last 30 days)
Iryna Maliatsina
Iryna Maliatsina on 22 Sep 2019
Edited: Stephen23 on 22 Sep 2019
Hi!
I want to make a scatter plot of the weights (y-axis) versus the heights (x-axis), with healthy individuals plotted as green points, underweight individuals as blue points and overweight individuals as red points. I have a code for that but I want to use 'plot' instead of 'scatter'. When I am using plot it gives error - Error using plot Data must be a single matrix Y or a list of pairs X,Y. Error in matlab4 (line 20) plot (H(:,n),W(:,n),2,c,'*').
Thank you!
M=[75,164;67,168;43,152; 56,169; 78,170; 49,157;66,167; 71,181; 120,170]'
W=M(1,:)
H=M(2,:)/100
BMI=W./H.^2;
hold on
box on
for n = 1:length(BMI)
if BMI(n)>=18.5 &BMI(n)<=24.9
c = 'green';
else
c = 'red';
end
scatter (H(:,n),W(:,n),2,c,'*')
end

Answers (1)

Stephen23
Stephen23 on 22 Sep 2019
Edited: Stephen23 on 22 Sep 2019
You cannot just swap functions around and expect them to work: they have different calling syntaxes, so you need to call plot with appropriate inputs, which are not the same as scatter inputs. That is why you should read the documentation for each function that you use.
if ...
lf = 'g*';
else
lf = 'r*';
end
plot(H(:,n),W(:,n),lf)
See also:

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!