Uninterrupted segment length?
이전 댓글 표시
Let's say I have an array indexes:
Indexes = [1122221122111211112222222]
How do I get the length of uninterrupted 2s? I want to output to be
output=[ 4 2 1 7]
채택된 답변
추가 답변 (1개)
Roger Stafford
2016년 11월 28일
편집: Roger Stafford
2016년 11월 28일
f = find(diff([false,Indexes==2,false])~=0);
output = f(2:2:length(f))-f(1:2:length(f));
댓글 수: 1
Qisq
2018년 4월 27일
Very elegant solution. Thanks.
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!