Is it possible to sort a struct? I want to sort the third column.
0 should be in the first row and the highest value at the end (last row). The other values are not important and should be the same ranking.
Thank you.

댓글 수: 2

KSSV
KSSV 2020년 7월 23일
Yes, you can.....read about sort. It depends how your structure is.
Peter Meier
Peter Meier 2020년 7월 23일
T = struct2table( parameter.list); % convert the struct array to a table
sortedT = sortrows(T, 'value'); % sort the table by value
sortedS = table2struct(sortedT) % change it back to str
%it works but i just want to sort the lowest and highest value (rows)

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

 채택된 답변

Mohammad Sami
Mohammad Sami 2020년 7월 23일
편집: Mohammad Sami 2020년 7월 23일

0 개 추천

You can try like this.
% a = somestruct;
[~,index] = sortrows([a.Var3].');
a = a(index);

댓글 수: 2

Peter Meier
Peter Meier 2020년 7월 23일
Thank you so much
Stephen23
Stephen23 2020년 7월 23일
[~,index] = sort([a.Var3]);

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

질문:

2020년 7월 23일

댓글:

2020년 7월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by