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