sorting a cell array

2 vues (au cours des 30 derniers jours)
Jae-Hee Park
Jae-Hee Park le 26 Nov 2021
Réponse apportée : DGM le 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.

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by