Sort struct by field name

조회 수: 5 (최근 30일)
Mikel  Jimenez
Mikel Jimenez 2021년 7월 21일
답변: Mikel Jimenez 2021년 7월 21일
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
Mikel  Jimenez
Mikel Jimenez 2021년 7월 21일
편집: Jan 2021년 7월 21일
Hi,
I found the code that works for this:
[x,idx]=sort([Stimuli.Color]);
Stimuli=Stimuli(idx);
Problem solved:)
-Mikel
Matt J
Matt J 2021년 7월 21일
Problem solved:)
If so, you should submit it as an answer and Accept-click it.

댓글을 달려면 로그인하십시오.

채택된 답변

Mikel  Jimenez
Mikel Jimenez 2021년 7월 21일
This code works:
[x,idx]=sort([Stimuli.Color]);
Stimuli=Stimuli(idx);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by