Grouping sequence within interval

2 ビュー (過去 30 日間)
Benu
Benu 2020 年 5 月 17 日
コメント済み: Benu 2020 年 6 月 5 日
I got stuck in grouping my sequence.
How can I automatically grouping element of sequence? within interval for this case maybe 0.5
suppose I have 3 sequence
V1 = [0.73 0.74 0.77 0.78 0.79 11.17 11.18 11.19 11.20 11.22 11.23];
V2 = [0.71 0.78 0.76 6.04 6.08 6.01 11.38 11.4 11.1] ;
V3 = [0.73 0.74 0.75 4.29 4.33 7.83 7.85 11.38 11.34]
My expectation is to have a group as follows
G1 = {[0.73 0.74 0.77 0.78 0.79] ; [11.17 11.18 11.19 11.20 11.22 11.23]}
G2 = {[0.71 0.78 0.76] ; [6.04 6.08 6.01] ; [11.38 11.4 11.1] }
G3 = {[0.73 0.74 0.75] ; [4.29 4.33] ; [7.83 7.85] ; [11.38 11.34]}

採用された回答

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020 年 5 月 17 日
Something like this should do the trick for you
V1 = [0.73 0.74 0.77 0.78 0.79 11.17 11.18 11.19 11.20 11.22 11.23];
V2 = [0.71 0.78 0.76 6.04 6.08 6.01 11.38 11.4 11.1] ;
V3 = [0.73 0.74 0.75 4.29 4.33 7.83 7.85 11.38 11.34]
Vsorted = sort(V3); % Works also with V1, V2
NewSeqLocations = find(diff(Vsorted)>0.5); % 0.5 is your interval, i.e, maximum difference between adjacent numbers
NewSeqLocations = [0,NewSeqLocations,length(Vsorted)]; % Last sequence ends at last array element and starts at first element
Seq = cell(length(NewSeqLocations)-1,1); % Save sequences in cell array
for idx=1:length(Seq)
Seq{idx} = Vsorted(NewSeqLocations(idx)+1:NewSeqLocations(idx+1));
end
Seq{:}
ans =
0.730000000000000 0.740000000000000 0.750000000000000
ans =
4.290000000000000 4.330000000000000
ans =
7.830000000000000 7.850000000000000
ans =
11.340000000000000 11.380000000000001
  1 件のコメント
Benu
Benu 2020 年 6 月 5 日
I never think this kind of a way. this is really help me.
wonderful ! Thank you so much !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by