sorting a cell array

2 visualizzazioni (ultimi 30 giorni)
Jae-Hee Park
Jae-Hee Park il 26 Nov 2021
Risposto: DGM il 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.

Risposta accettata

DGM
DGM il 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]}

Più risposte (0)

Categorie

Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by