How can I sort valus of a field in struct?

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 Comment

Is R a scalar struct or a struct array? Are the contents of the weights field scalars?

Sign in to comment.

 Accepted Answer

Maybe:
[~, index] = sort([R.weights]);
sortedR = R(index)

1 Comment

R is a struct array;
the content of the weights are scalar

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2017a

Tags

Asked:

on 30 Apr 2021

Commented:

on 1 May 2021

Community Treasure Hunt

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

Start Hunting!