Plot a histogram of all the BMI obtained in the while loop

4 visualizzazioni (ultimi 30 giorni)
This is my program. My question: I want to plot a histogram of all the different BMI obtained from different weight and hieght in the loop
fprintf('************************WELCOME TO WEEKLY DIET PLAN***********************\n')
% A MATLAB Program will be designed to input Patient_Name, Age, Height in
% inches and Weight in lbs from the user as follows
Patient_Name=input('Enter your name:','s');
Age=input('Enter your Age: ');
Weight=input('Enter your Weight in lbs: ');
Height=input('Enter your Height in inches:');
BMI= Weight*703./Height^2
fid=fopen('patientfile.txt','w');
fprintf(fid,'\t\t\t\t\t***********Patient Report***********\t\t\t\t\t\n')
fprintf(fid,'The BMI calculated for %s with %d lbs Weight and %d inches Height is %.2f \n',Patient_Name,Weight,Height,BMI)
if (BMI<18.5)
fprintf(fid,'Patient is Underweight\n')
elseif(18.5<BMI && BMI<24.9)
fprintf(fid,'Patient is Normal\n')
else(25<BMI & BMI<29.9);
fprintf(fid,'Patient is Overweight\n')
end
fprintf(fid,'\t\t\t\t\t***********Diet plan for the patieint***********\t\t\t\t\t\n')
Days=input('Enter number for what day is today(Mon=1|Tues=2|Wed=3|Thurs=4|Fri=5|Sat=6|Sun=7?: ');
Monday =1;
Tuesday =2;
Wednesday= 3;
Thusday =4;
Friday=5;
Saturday=6;
Sunday=7;
if Days==1
fprintf(fid,'Breakfast: Scrambled egg with any spinanch or tomato\n')
fprintf(fid,'Lunch: Tuna salad with lettuce, cucumber, and tomato\n ')
fprintf(fid,'Snack:Apple slices and peanut butter\n')
fprintf(fid,'Dinner: Bean chilli with cauliflower rice\n')
elseif Days==2
fprintf(fid,'Breakfast: Oatmeal with blueberries, milk, and chia seeds\n')
fprintf(fid,'Lunch: Hummus and vegetable wrap\n')
fprintf(fid,'Snack: Orange and cashew nuts\n')
fprintf(fid,'Dinner: Sesame salmon,with broccoli, and sweet potato mash\n')
elseif Days==3
fprintf(fid,'Breakfast: Mashed avocado and a fried egg on a slice of rye toast\n')
fprintf(fid,'Lunch: Broccoli quinoa and toasted almonds\n')
fprintf(fid,'Snack: Blueberries & coconut yogurt\n')
fprintf(fid,'Dinner: Chicken stir fry and bowl of Salad\n')
elseif Days==4
fprintf(fid,'Breakfast: Smoothie made with protein powder, berries, and oat milk\n')
fprintf(fid,'Lunch: Chicken salad with lettuce and corn\n')
fprintf(fid,'Snack: Whole grain rice cake with nut butter\n')
fprintf(fid,'Dinner: Roasted Mediterranean vegetables & lentils with tahini dressing\n')
elseif Days==5
fprintf(fid,'Breakfast: Buckwheat pancakes with raspberries and Greek yogurt\n')
fprintf(fid,'Lunch: Vegetable soup with two oatcakes\n')
fprintf(fid,'Snack: Boiled egg with pita slices\n')
fprintf(fid,'Dinner: Fish tacos with coleslaw\n')
elseif Days==6
fprintf(fid,'Breakfast: Apple slices with peanut butter\n')
fprintf(fid,'Lunch: Minted pea and feta omelette\n')
fprintf(fid,'Snack: Cocoa protein ball\n')
fprintf(fid,'Dinner: Baked sweet potato, chicken breast, greens\n')
elseif Days==7
fprintf(fid,'Breakfast: Breakfast muffin with eggs and vegetables\n')
fprintf(fid,'Lunch:Crispy tofu bowl\n')
fprintf(fid,'Snack:Carrot sticks and hummus\n')
fprintf(fid,'Dinner:Lentil soup with zucchini noodles\n')
end
count=1;
while true
loop= input ('continue?(1/0):')
if loop==1
Weight = input('Enter your current weight in lbs : ');
Height=input('Enter our current height in inches:');
BMI= Weight*703./Height^2;
fprintf(fid,'\t\t\t\t\t***********Patient Report after %d week***********\t\t\t\t\t\n',count)
fprintf(fid,'%s weight changed to %d lbs and Height is %d inches. The current BMI is %.2f \n',Patient_Name,Weight,Height,BMI)
else
break
end
if (BMI<18.5)
fprintf(fid,'Patient is Underweight\n')
elseif (18.5<BMI && BMI<24.9)
fprintf(fid,'Patient is Normal\n')
elseif (25<BMI && BMI<29.9)
fprintf(fid,'Patient is Overweight\n')
end
fprintf(fid,'\t\t\t\t\t***********Diet plan for the patieint***********\t\t\t\t\t\n')
Days=input('Enter number for what day is today(Mon=1|Tues=2|Wed=3|Thurs=4|Fri=5|Sat=6|Sun=7?: ');
Monday =1;
Tuesday =2;
Wednesday= 3;
Thusday =4;
Friday=5;
Saturday=6;
Sunday=7;
if Days==1
fprintf(fid,'Breakfast: Scrambled egg with any spinanch or tomato\n')
fprintf(fid,'Lunch: Tuna salad with lettuce, cucumber, and tomato\n ')
fprintf(fid,'Snack:Apple slices and peanut butter\n')
fprintf(fid,'Dinner: Bean chilli with cauliflower rice\n')
elseif Days==2
fprintf(fid,']Breakfast: Oatmeal with blueberries, milk, and chia seeds\n')
fprintf(fid,'Lunch: Hummus and vegetable wrap\n')
fprintf(fid,'Snack: Orange and cashew nuts\n')
fprintf(fid,'Dinner: Sesame salmon,with broccoli, and sweet potato mash\n')
elseif Days==3
fprintf(fid,'Breakfast: Mashed avocado and a fried egg on a slice of rye toast\n')
fprintf(fid,'Lunch: Broccoli quinoa and toasted almonds\n')
fprintf(fid,'Snack: Blueberries & coconut yogurt\n')
fprintf(fid,'Dinner: Chicken stir fry and bowl of Salad\n')
elseif Days==4
fprintf(fid,'Breakfast: Smoothie made with protein powder, berries, and oat milk\n')
fprintf(fid,'Lunch: Chicken salad with lettuce and corn\n')
fprintf(fid,'Snack: Whole grain rice cake with nut butter\n')
fprintf(fid,'Dinner: Roasted Mediterranean vegetables & lentils with tahini dressing\n')
elseif Days==5
fprintf(fid,'Breakfast: Buckwheat pancakes with raspberries and Greek yogurt\n')
fprintf(fid,'Lunch: Vegetable soup with two oatcakes\n')
fprintf(fid,'Snack: Boiled egg with pita slices\n')
fprintf(fid,'Dinner: Fish tacos with coleslaw\n')
elseif Days==6
fprintf(fid,'Breakfast: Apple slices with peanut butter\n')
fprintf(fid,'Lunch: Minted pea and feta omelette\n')
fprintf(fid,'Snack: Cocoa protein ball\n')
fprintf(fid,'Dinner: Baked sweet potato, chicken breast, greens\n')
elseif Days==7
fprintf(fid,'Breakfast: Breakfast muffin with eggs and vegetables\n')
fprintf(fid,'Lunch:Crispy tofu bowl\n')
fprintf(fid,'Snack:Carrot sticks and hummus\n')
fprintf(fid,'Dinner:Lentil soup with zucchini noodles\n')
end
count=count+1
end
fclose(fid)
x=BMI,BMI

Risposte (1)

Image Analyst
Image Analyst il 11 Dic 2021
Index BMI, like
BMI(count) = Weight*703./Height^2;
Then somewhere in the loop, call
histogram(BMI)

Community Treasure Hunt

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

Start Hunting!

Translated by