"If number belongs in the interval defined by a matrix" into code?

1 visualización (últimos 30 días)
ABCDEFG HIJKLMN
ABCDEFG HIJKLMN el 27 de Oct. de 2021
Comentada: ABCDEFG HIJKLMN el 27 de Oct. de 2021
Hello, I am trying to veto if two given numbers belong in two admissible ranges. Instead of writing line 11 that way, could I instead say something like if x_ini' does not belong to x_bound? Meaning that if the value of the first row of the transposed vector x_ini (i.e. x1_0) does not belong in the interval defined by the first row of matrix x_bound (i. e. x1_min x1_max) and/or, likewise, if the value of the second row of the transposed vector x_ini (i.e. x2_0) is not in the interval defined by the second row of matrix x_bound ((i. e. x2_min x2_max)), then that message is displayed?
Hopefully I have been clear? Thank you in advance for the help!
x1_min = 0.1;
x1_max = 2.0;
x2_min = 0.1;
x2_max = 2.5;
x_bound = [x1_min x1_max ; x2_min x2_max];
x1_0 = 1;
x2_0 = 1;
x_ini = [x1_0 x2_0];
if x1_0 < x1_min || x2_0 < x2_min || x1_0 > x1_max || x2_0 > x2_max
disp("Initial value of x does not belong in admissible interval.");
quit
end
  2 comentarios
Johan
Johan el 27 de Oct. de 2021
Hello, you can use:
if any([x_ini < x_bound(:,1)',x_ini > x_bound(:,2)'])

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by