Clear Filters
Clear Filters

My function isn't returning an array for an answer with an input array

1 view (last 30 days)
function [bodyMassIndex] = CalculateBMI(massKg, heightCm)
% Define a function CalculateBMI
% Input: massKg: Mass in kg
% heightCm: Height in cm
% Output: bodyMassIndex: Resulting BMI given mass and height
heightCm = heightCm / 100;
heightCm = nthroot(heightCm, 1/2);
bodyMassIndex= massKg / heightCm;
end
CalculateBMI([75, 90, 118], [178, 180, 200])

Accepted Answer

Walter Roberson
Walter Roberson on 8 Oct 2020
bodyMassIndex= massKg ./ heightCm;
The operator you used, /, is about the same as if you had written
bodyMassIndex= massKg * pinv(heightCm);

More Answers (0)

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!