function bmi = bmi_calculator(hw)
% Convert the height values from inches to meters
new_height= hw.height*2.54/100;
% Convert the weight values from lbs to kilograms
new_weight=hw.weight/2.2;
% Calculate the bmi for height and weight combination and return the output variable 'bmi'
bmi =new_weight./new_height.^2 ;
end
To test the code on MATLAB, the input hw was used as a table and it runs perfectly on MATLAB. But here it shows that the solution is wrong. Could anybody please explain?
The problem specifies that the input hw is a matrix with two columns (not a table). So, the error is saying that you cannot use dot indexing on a matrix.
Test | Status | Code Input and Output |
---|---|---|
1 | Fail |
hw = [66 155;60 140;72 166;58 160;75 215];
bmi_correct = [25.0700;27.3990;22.5607;33.5100;26.9293];
assert(all(abs(bmi_calculator(hw) - bmi_correct) < 1e-4))
|
2 | Fail |
hw = [10 80];
bmi_correct = 563.6375;
assert(all(abs(bmi_calculator(hw) - bmi_correct) < 1e-4))
|
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!