grouping indices based on how close they are

1 回表示 (過去 30 日間)
Dawid Strzelczyk
Dawid Strzelczyk 2020 年 11 月 20 日
回答済み: Bruno Luong 2020 年 11 月 20 日
Hi
Lets say, I have an array with indices like this:
a = [11 12 13 25 26 55 56 57]
Is there a nice way of grouping them into three (in this case) groups based on how close they are?
a1 = [11 12 13]; a2 = [25 26]; a3 = [55 56 57]
Best,
Dawid

採用された回答

Bruno Luong
Bruno Luong 2020 年 11 月 20 日
If your array is sorted
>> c = mat2cell(a,1,diff(find([true diff(a)>5 true]))); c{:}
ans =
11 12 13
ans =
25 26
ans =
55 56 57
>>

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by