Effacer les filtres
Effacer les filtres

Print a message if a condition is met

3 vues (au cours des 30 derniers jours)
Max
Max le 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 commentaire
Daniel Shub
Daniel Shub le 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))))

Connectez-vous pour commenter.

Réponses (2)

Matt Fig
Matt Fig le 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 le 28 Nov 2012
Modifié(e) : Ilham Hardy le 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)

Catégories

En savoir plus sur Entering Commands dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by