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 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by