how do i write commands for errors and warnings in Matlab
Show older comments
Q# Display an error message ‘Negative value(s), not acceptable.’ as long as one of the entered values is non-negative. (For this question i got the code below but i don't know if it is correct or not)
- function [BMI] = BMI (weight, height)
- BMI = (weight / (height^2));
- if ~isnumeric (weight) || ~isnumeric(height)
- error('Negative value(s), not acceptable.');
- end
Q# Display a warning message ‘Caution, value(s) may be invalid.’ to alert the user as long as one of the entered values is not reasonable, e.g. height > 2.5 or < 1.5 m; or weight < 30 or > 200 kg. (Can someone please help me writing code for this statement)
Answers (1)
John D'Errico
on 18 Mar 2022
Edited: John D'Errico
on 18 Mar 2022
1 vote
You wrote code for an ERROR message. If you don't know if it is correct, then TRY IT! Does it do as requested?
An error terminates execution, and that was not what you are supposed to do in the second question. So you need to do somethign different.
Instead, what does the function WARNING do? Read the help.
Categories
Find more on Introduction to Installation and Licensing 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!