sorting a cell array

1 view (last 30 days)
Jae-Hee Park
Jae-Hee Park on 26 Nov 2021
Answered: DGM on 26 Nov 2021
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.

Accepted Answer

DGM
DGM on 26 Nov 2021
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]}

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices 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!