sorting a cell array

조회 수: 2 (최근 30일)
Jae-Hee Park
Jae-Hee Park 2021년 11월 26일
답변: DGM 2021년 11월 26일
I have a cell data like this
cell = {3,1,6,[2,6,7],[4,10],10};
then i want to that cell becomes like this
cell = {1,[2,6,7],3,[4,10],6,10};
just sorting by the first values of each array.
please help me.

채택된 답변

DGM
DGM 2021년 11월 26일
Something like this:
C = {3,1,6,[2,6,7],[4,10],10}; % don't call it 'cell'
[~,idx] = sort(cellfun(@(x) x(1),C),'ascend');
C = C(idx)
C = 1×6 cell array
{[1]} {[2 6 7]} {[3]} {[4 10]} {[6]} {[10]}

추가 답변 (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