Sort cell elements according to one column

28 visualizzazioni (ultimi 30 giorni)
Xiaohan Du il 17 Gen 2018
Commentato: NALLARASU KRISH il 11 Mar 2022
Hi all,
I have a cell array like this:
K>> err
err =
3×6 cell array
[1] [ 1] [] [] [31×31 double] []
[2] [ 2] [] [] [31×31 double] []
[3] [1.5] [] [] [31×31 double] []
I'd like to sort it in ascending order of the 2nd column, in an order of 1, 1.5, 2, so it becomes
K>> err
err =
3×6 cell array
[1] [ 1] [] [] [31×31 double] []
[3] [1.5] [] [] [31×31 double] []
[2] [ 2] [] [] [31×31 double] []
How can I do it? Thanks!
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposta accettata

Guillaume il 17 Gen 2018
Modificato: Guillaume il 17 Gen 2018
[~, order] = sort(cell2mat(err(:, 2)));
sortederr = err(order, :)
edit: actually a lot simpler since sortrows works with cell arrays:
sortederr = sortrows(err, 2)
2 CommentiMostra NessunoNascondi Nessuno
Adnane Youcef il 4 Mar 2021
Thnx, it's work
NALLARASU KRISH il 11 Mar 2022
You are genius. Thank you!

Accedi per commentare.

Categorie

Scopri di più su Cell Arrays 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