How to find missing number in repeating sequence.

조회 수: 5 (최근 30일)
Ruben
Ruben 2014년 7월 29일
답변: Azzi Abdelmalek 2014년 7월 29일
The data I'm using has a numerical array of [1 2 3 4 1 2 3 4 1 2 3 4], which can be multiples of [1 2 3 4]. Now sometimes in one of the repeated sequences a number is missing. I would like to know which number and where, so I can add zeros to this position in my data. Example: [1 2 3 4 1 2 3 1 2 3 4], in this case I want to find that the second 4 is missing. Does anybody know a quick way to do this?
Ruben

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 29일
v=[1 2 3 4 1 2 3 1 2 3 4];
sequence=[1 2 3 4];
ii=find([1 diff(v)<=0]);
jj=[ii(2:end)-1 numel(v)];
for k=1:numel(ii)
out{k}=setdiff(sequence,v(ii(k):jj(k)));
end
celldisp(out)

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by