finding consecutive numbers in an array
6 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I'am trying to find minimum 320 consecutive numbers in an array. Is there any simple way to find it?
2 件のコメント
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?
回答 (1 件)
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!