Sort cell elements according to one column

31 visualizaciones (últimos 30 días)
Xiaohan Du
Xiaohan Du el 17 de En. de 2018
Comentada: NALLARASU KRISH el 11 de Mzo. de 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!

Respuesta aceptada

Guillaume
Guillaume el 17 de En. de 2018
Editada: Guillaume el 17 de En. de 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 comentarios
Adnane Youcef
Adnane Youcef el 4 de Mzo. de 2021
Thnx, it's work
NALLARASU KRISH
NALLARASU KRISH el 11 de Mzo. de 2022
You are genius. Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by