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!