sorting a cell array

1 回表示 (過去 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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by