Sort cell elements according to one column

31 ビュー (過去 30 日間)
Xiaohan Du
Xiaohan Du 2018 年 1 月 17 日
コメント済み: NALLARASU KRISH 2022 年 3 月 11 日
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!

採用された回答

Guillaume
Guillaume 2018 年 1 月 17 日
編集済み: Guillaume 2018 年 1 月 17 日
[~, order] = sort(cell2mat(err(:, 2)));
sortederr = err(order, :)
edit: actually a lot simpler since sortrows works with cell arrays:
sortederr = sortrows(err, 2)
  2 件のコメント
Adnane Youcef
Adnane Youcef 2021 年 3 月 4 日
Thnx, it's work
NALLARASU KRISH
NALLARASU KRISH 2022 年 3 月 11 日
You are genius. Thank you!

サインインしてコメントする。

その他の回答 (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