2017-05-04 4 views
-1

나는 모든 숫자가 매 5 분마다 측정되는 Matlab 행렬을 가지고 있습니다.숫자 행렬 색인을 얻는 방법?

5 개 이상의 0으로 구분 된 모든 블록의 시작 및 끝 인덱스를 어떻게 찾을 수 있습니까? 그것은 오른쪽에서부터 시작하여 5보다 큰 0을 찾을 때까지 블록을 계속합니다. 즉

1 0 0 4 0 1 2 0 0 0 0 0 0 4 2 22 41 0 0 0 0 0 5 6 0 0 0 4 

블록은 다음과 같습니다

4 2 22 41 0 0 0 0 0 5 6 0 0 0 4 
1 0 0 4 0 1 2 

그리고 나는 그들의 인덱스를 알고 싶어요.

어떻게하면됩니까?

+0

관련 : http://stackoverflow.com/questions/3274043/finding-islands-of-zeros-in-a-sequence – excaza

답변

1

이미지 처리 도구 상자이있는 경우이 목적으로 bwareaopen을 사용할 수 있습니다. 지정된 배열의 경우

A = [1 0 0 4 0 1 2 0 0 0 0 0 0 4 2 22 41 0 0 0 0 0 5 6 0 0 0 4]; %Given array 
tmp=~bwareaopen(~A, 6); %Logical array of the blocks separated by greater than 5 zeros 
tmp = diff([0, tmp, 0]); %Padded with zeroes for the first & last indices respectively 
startInd = find(tmp == 1); %starting indices of the blocks 
endInd = find(tmp == -1) - 1; %ending indices of the blocks 

, 그것은 제공 :

>> startInd 

startInd = %1st block starts from the 1st index, 2nd block starts from the 14th index 
    1 14 

>> endInd 

endInd =  %1st block ends at the 7th index, 2nd block ends at the 28th index 
    7 28 
관련 문제