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 个评论

Yes, you can.....read about sort. It depends how your structure is.
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
You can try like this.
% a = somestruct;
[~,index] = sortrows([a.Var3].');
a = a(index);

更多回答(0 个)

类别

帮助中心File 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