How can i simplify this

1 回表示 (過去 30 日間)
Pablo Zarco
Pablo Zarco 2021 年 8 月 12 日
編集済み: DGM 2021 年 8 月 13 日
If (a(i)>0)&&(a(i-1)==0)&&(a(i-2)==0)&&(a(i-3)==0)&&(a(i-4)==0)&&(a(i-5)==0)&&(a(i-6)==0)...until a(i-32)==0

回答 (2 件)

Star Strider
Star Strider 2021 年 8 月 12 日
I have no idea what you are askiing.
See if the all or any functions will work with whatever you are doing.
.
.

DGM
DGM 2021 年 8 月 13 日
編集済み: DGM 2021 年 8 月 13 日
Like Star Strider mentioned, you can use all() or any()
a(i)>0 && ~any(a(i-32:i-1))
but there are a couple things to mention.
First is whether a is an integer class. If it's not, then testing for equality with zero is likely going to cause problems. Test to within some tolerance.
a(i)>0 && all(abs(a(i-32:i-1)-0)<tolerance)
Second is whether you're making sure a(i-32), etc exist. You may need to pad the vector or restrict the indexing accordingly.

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by