Resort struct elements by one field values
Mostrar comentarios más antiguos
Hello,
In a struct
A = struct('f1', [some values], 'f2', [some values])
Can we resort elements of A by increasing order in f1?
For example:
A = struct('f1', [some values], 'f2', [some values])
A.f1 is a 1 X 5 double value [3, 4, 1, 2, 5]
A.f2 is 1 X 5 double value [val 3, val 4, val 1, val 2, val 5]
How to create another struct B as
B = struct('f1', [1 , 2, 3, 4, 5], 'f2', [val 1, val 2, val 3, val 4, val 5])?
1 comentario
Walter Roberson
el 6 de Mzo. de 2011
One can re-sort in Matlab, and one can resort -to- Matlab, but I didn't know of any Matlab Resort ;-)
Respuesta aceptada
Más respuestas (1)
Giovanni Soldi
el 6 de Mzo. de 2011
Try in this way:
B = struct('f1',sort(A.f1),'f2',sort(A.f2));
Categorías
Más información sobre Shifting and Sorting Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!