sort cell array in a struct

조회 수: 3 (최근 30일)
Chiara Scarpellini
Chiara Scarpellini 2021년 8월 7일
답변: Walter Roberson 2021년 8월 8일
I need to sort the vector Codes and I need the values of vector Discharge to be ordinated according to it. I tried the function sortrows but in this case it doesn't work since in soe cases I'm not working with scalars.
  댓글 수: 6
Walter Roberson
Walter Roberson 2021년 8월 7일
편집: Walter Roberson 2021년 8월 8일
[Name_Code.Codes, Cidx] = cellfun(@sort,Name_Code.Codes,"UniformOutput",false);
Name_Code.Discharge = cellfun(@(d,idx)d(idx), Name_Code.Discharge, Cidx);
Chiara Scarpellini
Chiara Scarpellini 2021년 8월 7일
it works! huge thank you!

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2021년 8월 8일
(Moving down from comment)
[Name_Code.Codes, Cidx] = cellfun(@sort,Name_Code.Codes,"UniformOutput",false);
Name_Code.Discharge = cellfun(@(d,idx)d(idx), Name_Code.Discharge, Cidx);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by