How can I sort valus of a field in struct?

1 vue (au cours des 30 derniers jours)
Mira le
Mira le le 30 Avr 2021
Commenté : Mira le le 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 commentaire
Jan
Jan le 1 Mai 2021
Is R a scalar struct or a struct array? Are the contents of the weights field scalars?

Connectez-vous pour commenter.

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Tags

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by