Borrar filtros
Borrar filtros

evaluate whether a condition is met

2 visualizaciones (últimos 30 días)
Max
Max el 27 de Nov. de 2012
Hi all, I have to evaluate whether a condition is met: this is the basic method:
if a1 < b1 < a2
disp ('ok')
else disp ('error')
end
If I had n "b" and n+1 "a" I should write n if or is there a way to simplify it? if so how? thank you very much
  1 comentario
Matt J
Matt J el 27 de Nov. de 2012
Editada: Matt J el 27 de Nov. de 2012
I assume you really mean
if a1 < b1 & b1 < a2
disp ('ok')
else disp ('error')
end

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 27 de Nov. de 2012
Editada: Matt J el 27 de Nov. de 2012
Assuming size(a) is [1,n+1] and size(b) is [1,n]
if a(1:end-1)<b & b<a(2:end)

Más respuestas (2)

Max
Max el 27 de Nov. de 2012
Perfect! Now, for example, If during the second cycle the condition is not satisfied, the overall result will be error; it is possible to print statements that do not meet this condition?
I hope I was clear ;)
Max

Max
Max el 27 de Nov. de 2012
Sorry Matt J, I read only now you precondition that
a1 < b1 & b1 < a2
in my situation I have to evaluate if a value is in-range or is out-range. the value have to be in its range
For example:
a_1 < b_1 < a_2
a_2 < b_2 < a_3
a_n < b_n < a_n+1
etc.
and
b_1 = a_1 + x_1
b_2 = a_2 + x_2
b_n = a_n + x_n
etc
x is a column-vector of n elements;
is correct if I do:
if a(1:end-1) < (a(1:end-1) + x(1:end) ) < a(2:end-1)
  6 comentarios
Matt J
Matt J el 28 de Nov. de 2012
You should post this as a new question and make it clearer. We would probably need a specific example showing the output that you want.
Max
Max el 28 de Nov. de 2012
ok ;)

Iniciar sesión para comentar.

Categorías

Más información sobre Animation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by