How can I sort valus of a field in struct?

1 Ansicht (letzte 30 Tage)
Mira le
Mira le am 30 Apr. 2021
Kommentiert: Mira le am 1 Mai 2021
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 Kommentar
Jan
Jan am 1 Mai 2021
Is R a scalar struct or a struct array? Are the contents of the weights field scalars?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 1 Mai 2021
Maybe:
[~, index] = sort([R.weights]);
sortedR = R(index)
  1 Kommentar
Mira le
Mira le am 1 Mai 2021
R is a struct array;
the content of the weights are scalar

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by