Problem 44945. Calculate BMI
- 1 kilogram = 2.2 pounds
- 1 inch = 2.54 centimeters
- BMI = weight(kg) / [height(m)]^2
Solution Stats
Problem Comments
-
18 Comments
function bmi = bmi_calculator(hw)
% Convert the height values from inches to meters
h=reshape(hw(:,1),1,[]);
h=0.0254*h;
% Convert the weight values from lbs to kilograms
w=reshape(hw(:,2),1,[]);
w=(1/2.2)*w;
% Calculate the bmi for height and weight combination and return the output variable 'bmi'
bmi=w./(h.^2);
end
what is wrong with this, please help. It runs fine on RUN button but does not pass the test
@Prathamesh Using your code, bmi is returned as a row vector, but the test suite expects a column vector.
In this excercise the big deal is to recognice that the solution must be in the same format as the entry data. That in this case is a Column Vector.
Solution Comments
Show commentsGroup

MATLAB Onramp Practice
- 15 Problems
- 4527 Finishers
- Times 2 - START HERE
- Calculate Amount of Cake Frosting
- Convert from Fahrenheit to Celsius
- Find the Oldest Person in a Room
- Verify Law of Large Numbers
- Solve a System of Linear Equations
- Calculate a Damped Sinusoid
- Plot Damped Sinusoid
- Calculate BMI
- Crop an Image
- Find the Best Hotels
- Find MPG of Lightest Cars
- Calculate Inner Product
- Rescale Scores
- Longest run of consecutive numbers
Problem Recent Solvers9577
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!