필터 지우기
필터 지우기

Finding series of repeating numbers in matrix

조회 수: 3 (최근 30일)
Michael Saniuk
Michael Saniuk 2017년 5월 13일
댓글: Michael Saniuk 2017년 5월 13일
Hello, I am trying to find begginings and endings of repeating zeros in matrix, eg: for input matrix:
1 0 0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 1
I want to get:
beggining = [2 9 14 21 25]
ending = [6 10 18 23 26]
Does anyone know how to do it?

채택된 답변

Stephen23
Stephen23 2017년 5월 13일
편집: Stephen23 2017년 5월 13일
>> V = [1,0,0,0,0,0,1,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,1,0,0,1];
>> D = [V(1)==0,diff(V==0)];
>> find(D>0)
ans =
2 9 14 21 25
>> find(D<0)-1
ans =
6 10 18 23 26

추가 답변 (1개)

Guillaume
Guillaume 2017년 5월 13일
v = [1 0 0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 1]
beginning = strfind([1 v], [1 0])
ending = strfind([v 1], [0 1])
Despite its name, strfind works with sequence of numbers as well.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by