How can I sort valus of a field in struct?

1 次查看(过去 30 天)
Hello Everyone
I have an issue to sort values so
I have struct named R contains field : sequance [ ]
Cost [ ]
weights (value)
I want to sort R according to weights in ascending order
please help me.
Thank you
  1 个评论
Jan
Jan 2021-5-1
Is R a scalar struct or a struct array? Are the contents of the weights field scalars?

请先登录,再进行评论。

采纳的回答

Jan
Jan 2021-5-1
Maybe:
[~, index] = sort([R.weights]);
sortedR = R(index)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by