how do i write commands for errors and warnings in Matlab
Ältere Kommentare anzeigen
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)
Antworten (1)
John D'Errico
am 18 Mär. 2022
Bearbeitet: John D'Errico
am 18 Mär. 2022
1 Stimme
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.
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!