How can I sort valus of a field in struct?

1 visualizzazione (ultimi 30 giorni)
Mira le
Mira le il 30 Apr 2021
Commentato: Mira le il 1 Mag 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 Commento
Jan
Jan il 1 Mag 2021
Is R a scalar struct or a struct array? Are the contents of the weights field scalars?

Accedi per commentare.

Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Tag

Prodotti


Release

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by