how do i write commands for errors and warnings in Matlab

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)
  1. function [BMI] = BMI (weight, height)
  2. BMI = (weight / (height^2));
  3. if ~isnumeric (weight) || ~isnumeric(height)
  4. error('Negative value(s), not acceptable.');
  5. 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)

Réponses (1)

John D'Errico
John D'Errico le 18 Mar 2022
Modifié(e) : John D'Errico le 18 Mar 2022
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.

Catégories

Produits

Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by