finding consecutive numbers in an array

조회 수: 5 (최근 30일)
Huseyin
Huseyin 2016년 1월 31일
편집: Jan 2016년 1월 31일
Hi,
I'am trying to find minimum 320 consecutive numbers in an array. Is there any simple way to find it?
  댓글 수: 2
Jan
Jan 2016년 1월 31일
편집: Jan 2016년 1월 31일
Please explain the term "consecutive numbers" in an example. Do you mean, that the difference between two neigboring numbers is +1? Or is -1 accepted also? Do you mean integer values in a double array? Which result is wanted? The first index? What exactly is "minimum 320 numbers"? I assume it is a block of 320 or more elements?
Huseyin
Huseyin 2016년 1월 31일
Assume that I have an array like;
a= [8 9 10 11 15 16 17 180 181 182 183 184 185 190]
In that 1x14 double, I want to find the beginning and end of the consecutive 6 numbers. Answer should be like it begins at 180 and ends with 185

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

답변 (1개)

Jan
Jan 2016년 1월 31일
편집: Jan 2016년 1월 31일
Data = randi([1, 10], 1, 1e6); % Any test data
Len = 5; % 320 in your case
[B, N, Index] = RunLength(diff(Data));
Match = find(N >= Len & B == 1);
% Output to control results:
for k = 1:numel(Match)
iResult = Index(Match(k));
fResult = iResult + N(Match(k)) - 1;
disp(Data(iResult:fResult));
end
  댓글 수: 2
Huseyin
Huseyin 2016년 1월 31일
편집: Huseyin 2016년 1월 31일
I set your RunLength package to the path but Matlab gives a message like 'too many output arguments'. It gives the same message for your example also.
Jan
Jan 2016년 1월 31일
편집: Jan 2016년 1월 31일
Please post a complete copy of the error message.
Start RunLength once without input arguments for a compilation of the C-code. If you do not have a C-compiler, use the slower RunLength_M.

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

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by