Filter löschen
Filter löschen

Print a message if a condition is met

3 Ansichten (letzte 30 Tage)
Max
Max am 28 Nov. 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 Kommentar
Daniel Shub
Daniel Shub am 28 Nov. 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))))

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Matt Fig
Matt Fig am 28 Nov. 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 am 28 Nov. 2012
Bearbeitet: Ilham Hardy am 28 Nov. 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)

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by