필터 지우기
필터 지우기

Find order of increasing integers

조회 수: 1 (최근 30일)
Sebastian Daneli
Sebastian Daneli 2021년 6월 15일
댓글: Sebastian Daneli 2021년 6월 15일
I have a vector
[3,4,8,9,10,13]
How can I sort this into
[3,4]; [8,9,10]; [13];
in an efficient way? I.e., split the parts of the vector where there is a linear increase of +1 from the previous entry.

채택된 답변

Stephen23
Stephen23 2021년 6월 15일
편집: Stephen23 2021년 6월 15일
V = [3,4,8,9,10,13];
D = diff(find([true,diff(V)~=1,true]));
C = mat2cell(V,1,D)
C = 1×3 cell array
{[3 4]} {[8 9 10]} {[13]}

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by