Sort cell elements according to one column

조회 수: 37 (최근 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 CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by