How to use if elseif, if

11 views (last 30 days)
THANH NGUYEN
THANH NGUYEN on 11 Feb 2013
Underweight: BMI is less than 18.5 Normal weight: BMI is 18.5 to 24.9 Overweight: BMI is 25 to 29.9 Obese: BMI is 30 or more how to use if, elseif, if to Display BMI classification I did:
if(BMI<18.5)
BMI classification='underweight'
elseif(18.5<BMI<24.9)
BMI classification='Normal weight'
else(25<BMI<29.9)
BMI classification='Overweight'
end

Answers (1)

Youssef  Khmou
Youssef Khmou on 11 Feb 2013
Hi try this :
BMI=input(' Enter BMI : ');
if(BMI<18.5)
classification='underweight'
elseif(18.5<BMI && BMI<24.9)
classification='Normal weight'
else(25<BMI && BMI<29.9)
classification='Overweight'
end
  2 Comments
THANH NGUYEN
THANH NGUYEN on 11 Feb 2013
How about obese for BMI greater than 30?
Image Analyst
Image Analyst on 11 Feb 2013
Edited: Image Analyst on 11 Feb 2013
if BMI < 18.5
classification='underweight'
elseif 18.5 <= BMI && BMI < 24.9
classification='Normal weight'
elseif 24.9 <= BMI && BMI < 30
classification='Overweight'
else
classification='Obese'
end

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!