how do i write commands for errors and warnings in Matlab

1 visualización (últimos 30 días)
Radhika Oad
Radhika Oad el 18 de Mzo. de 2022
Editada: John D'Errico el 18 de Mzo. de 2022
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)

Respuestas (1)

John D'Errico
John D'Errico el 18 de Mzo. de 2022
Editada: John D'Errico el 18 de Mzo. de 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.

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by