if loop with multiple conditions

I have a matix 80x1. Now i want band of values to be executed:
The band is: 1-14, 29-33, 40-54, 69-73.
It should ignore all the values not included in the above band.
For this, I tried if-loop with the conditions like,
if k < 14 || k > 29 && k < 33 || k > 40 && k < 54|| k > 69 && k < 73
then...
end
However, this does not work. i mean, it works fine only upto k=33
Any help?

 採用された回答

madhan ravi
madhan ravi 2018 年 10 月 25 日
編集済み: madhan ravi 2018 年 10 月 25 日

0 投票

k=1:80
idx = ( k >= 1 & k <= 14 | k >=29 & k <= 33 | k >= 69 & k <=73)
k(idx)=[]

3 件のコメント

Megha
Megha 2018 年 10 月 25 日
Can you please explain, What difference does that make?
madhan ravi
madhan ravi 2018 年 10 月 25 日
see the above example it finds the index of the values that falls inside that band and in the next step those values are removed , which in this case is your desired result
madhan ravi
madhan ravi 2018 年 10 月 25 日
編集済み: madhan ravi 2018 年 10 月 25 日
What difference does that make?
& evaluates both conditions but && evaluates only if right hand side is true for detailed explanation see difference between & and &&
Loop is not necessary for this , smoother and efficient by this way though

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2018 年 10 月 25 日

編集済み:

2018 年 10 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by