Borrar filtros
Borrar filtros

Print a message if a condition is met

3 visualizaciones (últimos 30 días)
Max
Max el 28 de Nov. de 2012
Hi all, I have 8 ranges:
[ x(1) , x(2) ] , [ x(2) , x(3) ] ... [ x(7) , x(8) ]
memorized in a column-vector, x :
x = [x(1); x(2); ... ; x(8)]
and 7 values
p(1), p(2), ... , p(7)
I have to print only the values that are included in the corresponding range,
x(1) < p(1) & p(1) < x(2)
x(2) < p(2) & p(2) < x(3)
... so
x(1:end-1) < p(1:end) & p(1:end) < x(2:end)
With:
disp(find(~(x(1:end-1) < p(1:end) & p(1:end) < x(2:end))))
I print all the values that are outside of own range.
My goal is print also the values that are inside of own range. Thanks
Max
  1 comentario
Daniel Shub
Daniel Shub el 28 de Nov. de 2012
Maybe I am missing something but can't you just remove the ~?
disp(find((x(1:end-1) < p(1:end) & p(1:end) < x(2:end))))

Iniciar sesión para comentar.

Respuestas (2)

Matt Fig
Matt Fig el 28 de Nov. de 2012
x = [1;2;3;4];
p = [1.5;3.5;3.2];
idx = x(1:end-1)<p & p<x(2:end);
SOL = p(idx)

Ilham Hardy
Ilham Hardy el 28 de Nov. de 2012
Editada: Ilham Hardy el 28 de Nov. de 2012
xa = [3;5;7;9;11;13;15;17];
ya = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
res = ya(find(ya>xa(1)& ya<xa(end)&~ismember(ya,xa)));
disp(res)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by