How can i simplify this
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (2개)
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!