Puzzler: Count unique nonzero periods in a timeseries without a for loop
조회 수: 1 (최근 30일)
이전 댓글 표시
given: a signal as a time series
return: discrete number of times is is holds a nonzero position
For example:
given: [0,1,0.5,0.7,0,1]
return: 2
given: [0,1,0,0,0,.3,1,0,0,1]
return: 3
given: [0,1]
return: 1
is there a way to do this task in a vector manner as opposed to a for loop that counts nonzero periods as it encounters them and flicks a counter.
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2016년 7월 19일
편집: Azzi Abdelmalek
2016년 7월 19일
a=[0,1,0,0,0,.3,1,0,0,1]
out=numel(strfind([0 logical(a)],[0 1]))
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Electromechanical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!