필터 지우기
필터 지우기

I have an array [0,0,0,0,1​23,0,138,4​4,123,0,0,​0,0,0,135,​0,123,0,0,​125.......​.] I want to find starting and ending index for pattern [123,0] like[5,6,9,10....] Please help me find the ending indices

조회 수: 1 (최근 30일)
I can find the starting index using below function. function start = findPattern2(array, pattern)
len = length(pattern);
start = find(array==pattern(1));
endVals = start+len-1; start(endVals>length(array)) = [];
for pattval = 2:len
locs = pattern(pattval) == array(start+pattval-1);
start(~locs) = [];
end

채택된 답변

Jan
Jan 2018년 6월 14일
편집: Jan 2018년 6월 14일
pattern = [123, 0];
a = [0,0,0,0,123,0,138,44,123,0,0,0,0,0,135,0,123,0,0,125];
idx = strfind(a, [123,0]);
result = reshape([idx; idx + length(pattern) - 1], 1, []);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by