How to plot in for loop?

1 次查看(过去 30 天)
torre
torre 2019-9-21
评论: torre 2019-9-24
I'm trying to plot in loop a vector that has body mass index values. Purpose is to plot different weight category like undereight in blue and overweight in red and so on but i can't get my loop working properly. Can somebody help?
here is my code
data =[75 67 43 56 78 49 66 71 120
164 168 152 169 170 157 167 181 170];
weight=data(1,:)
heigth=data(2,:)
bmi=weight./((heigth/100).^2);
for i = 1:length(bmi)
if i<18.5
scatter(heigth,weight,i,'b*')
elseif i>24.9
scatter(heigth,weight,i,'r*')
else
scatter(heigth,weight,i,'g*')
end
end
grid on
xlabel('height (m)')
ylabel('weight (kg)')

采纳的回答

darova
darova 2019-9-21
You re comparing wrong variable
if i<18.5 % maybe bmi(i) < 18.5
Forgot hold on
hold on
You draw all data together instead of one point
scatter(heigth,weight,i,'r*') % maybe plot(heigth(i),weight(i),'r*')
  1 个评论
torre
torre 2019-9-24
Thank you. Now I understand the logic in this code.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by