How can I segment a matrix based on the difference between a column's elements of the matrix?
1 view (last 30 days)
Show older comments
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
]
0 Comments
Accepted Answer
Torsten
on 18 Sep 2022
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)
0 Comments
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!