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일

0 개 추천

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:

카테고리

도움말 센터File Exchange에서 Scatter Plots에 대해 자세히 알아보기

태그

질문:

2019년 9월 22일

편집:

2019년 9월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by