Count Zeros Length Matrix Into an Array

조회 수: 1 (최근 30일)
Angga Lisdiyanto
Angga Lisdiyanto 2016년 1월 18일
편집: Angga Lisdiyanto 2016년 1월 18일
I want to get all length of zero values alternately and consecutively. In example :
m = [0 0 0 0 1 2 2 0 0 5 3 4 5 0 0 0 0 0 9 9 0 0 0];
Result that i need is : zero = [4 2 5 3]
So, i need to count the 0 values in each of alternately. Thanks in advance.

채택된 답변

Stephen23
Stephen23 2016년 1월 18일
>> m = [0 0 0 0 1 2 2 0 0 5 3 4 5 0 0 0 0 0 9 9 0 0 0];
>> x = find(diff([false,m==0,false]));
>> x(2:2:end)-x(1:2:end)
ans =
4 2 5 3
  댓글 수: 1
Angga Lisdiyanto
Angga Lisdiyanto 2016년 1월 18일
편집: Angga Lisdiyanto 2016년 1월 18일
Thank you very much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by