My function isn't returning an array for an answer with an input array
3 次查看(过去 30 天)
显示 更早的评论
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])
采纳的回答
Walter Roberson
2020-10-8
bodyMassIndex= massKg ./ heightCm;
The operator you used, /, is about the same as if you had written
bodyMassIndex= massKg * pinv(heightCm);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!