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 で Structures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by