Scatter works but Plot gives error

2 次查看(过去 30 天)
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

回答(1 个)

Stephen23
Stephen23 2019-9-22
编辑:Stephen23 2019-9-22
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:

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by