フィルターのクリア

How can I segment a matrix based on the difference between a column's elements of the matrix?

1 回表示 (過去 30 日間)
I have a matrix (X), I want it to be segmented such that for each segment, the difference between successive first column entries does not exceed 6. The output should be as (xx) or call it whatever.
%%% The INPUT %%%
X=[
8.3700 -53.3090
11.4000 -116.6670
13.0000 -117.8350
26.7000 -105.8580
36.4000 -121.5060
39.4000 -116.0400
65.1000 -95.1370
65.9000 -123.0920
70.3000 -133.5950
122.0000 -113.7320
]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% The OUTPUT %%%
xx=[
8.3700 -53.3090
11.4000 -116.6670
13.0000 -117.8350
]
xx=[
26.7000 -105.8580
]
xx=[
36.4000 -121.5060
39.4000 -116.0400
]
xx=[
65.1000 -95.1370
65.9000 -123.0920
70.3000 -133.5950
]
xx=[
122.0000 -113.7320
]

採用された回答

Torsten
Torsten 2022 年 9 月 18 日
X=[
8.3700 -53.3090
11.4000 -116.6670
13.0000 -117.8350
26.7000 -105.8580
36.4000 -121.5060
39.4000 -116.0400
65.1000 -95.1370
65.9000 -123.0920
70.3000 -133.5950
122.0000 -113.7320
];
i = find(abs(diff(X(:,1)))>6);
i = [i(1);diff(i);size(X,1)-i(end)];
xx = mat2cell(X,i)
xx = 5×1 cell array
{3×2 double } {[26.7000 -105.8580]} {2×2 double } {3×2 double } {[ 122 -113.7320]}

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by