フィルターのクリア

Print a message if a condition is met

3 ビュー (過去 30 日間)
Max
Max 2012 年 11 月 28 日
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 件のコメント
Daniel Shub
Daniel Shub 2012 年 11 月 28 日
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))))

サインインしてコメントする。

回答 (2 件)

Matt Fig
Matt Fig 2012 年 11 月 28 日
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 2012 年 11 月 28 日
編集済み: Ilham Hardy 2012 年 11 月 28 日
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)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by