Sort struct by field name

11 Ansichten (letzte 30 Tage)
Mikel  Jimenez
Mikel Jimenez am 21 Jul. 2021
Beantwortet: Mikel Jimenez am 21 Jul. 2021
Hello,
I have the following struct:
I was wondering how to, using some code, reorganize the struct (i.e. sort it) according to the values in the Color field. So, all the blue would be together and then and then all the red. Can't find a clear solution, any help would be very much appreciated.
Thanks,
Mikel
  2 Kommentare
Mikel  Jimenez
Mikel Jimenez am 21 Jul. 2021
Bearbeitet: Jan am 21 Jul. 2021
Hi,
I found the code that works for this:
[x,idx]=sort([Stimuli.Color]);
Stimuli=Stimuli(idx);
Problem solved:)
-Mikel
Matt J
Matt J am 21 Jul. 2021
Problem solved:)
If so, you should submit it as an answer and Accept-click it.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mikel  Jimenez
Mikel Jimenez am 21 Jul. 2021
This code works:
[x,idx]=sort([Stimuli.Color]);
Stimuli=Stimuli(idx);

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by