How to plot in for loop?
1 次查看(过去 30 天)
显示 更早的评论
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)')
0 个评论
采纳的回答
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*')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!