I don't know how to make and algorithm to find BMI?
1 次查看(过去 30 天)
显示 更早的评论
I don't know how to make a MATLAB program that calculates BMI?
0 个评论
回答(1 个)
Vilém Frynta
2023-2-3
This looks like homework.
Try creating a function. Inputs will be height and weight, and output will be the BMI.
Some useful links that might help you:
10 个评论
Walter Roberson
2023-2-5
make sure you put the function code into myFunction.m
Also, make sure you did not write the function inside one of MATLAB's installation directories. MATLAB assumes that any program or person that modifies the installation directories will specifically tell MATLAB to check for new files. This is unlike if your current directory is one of your own directory and you use the MATLAB editor to modify (or create) the file: in that case, MATLAB will notice the change and permit the function to be called.
DGM
2023-2-5
编辑:DGM
2023-2-5
If you're putting the function into a script, then you won't be able to call from the command line. It's local to the script, so you call it within the script.
% this is a script
% call the local function
result = myfunction(5)
% this is a local function within a script
function out = myfunction(in)
out = in*10;
end
Otherwise, you can create a function file and place it somewhere on the path. Then you can call it where ever you want. See Star Strider's link.
Note that while you can turn any script into a function, function files contain only functions, and are treated differently than script files. Unless you've structured the file as a function, you'll have issues trying to execute it as a function.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!