sort a structure
2 次查看(过去 30 天)
显示 更早的评论
Is it possible to create a structure that holds the following information:
- id_number
- length
such that I can then sort the structure by length from largest to smallest. I then want to retrieve the id_number for the top 5 elements.
0 个评论
采纳的回答
Daniel Shub
2011-9-28
something like:
s = struct('id_number', mat2cell(1:100, 1, ones(100, 1)), 'length', mat2cell(rand(1, 100), 1, ones(100, 1)));
[a, b] = sort([s.length]);
[s(b(1:5)).id_number]
更多回答(0 个)
另请参阅
类别
在 Help Center 和 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!