Sorting variable names in alphabetical order

조회 수: 10 (최근 30일)
Jonny Coltraine
Jonny Coltraine 2012년 11월 20일
댓글: Ahmet Selçuk 2022년 11월 1일
Using the workspace window, wow can I sort variables defined inside a struct object in alphabetical order? clicking on the Field column doesn't sort them.

채택된 답변

José-Luis
José-Luis 2012년 11월 20일
편집: José-Luis 2012년 11월 20일
Looks like you might want to use orderfields()
a.b = 1;
a.a = 2;
a.m = 4;
a.h = 5
a =
b: 1
a: 2
m: 4
h: 5
a = orderfields(a)
a =
a: 2
b: 1
h: 5
m: 4
  댓글 수: 1
Ahmet Selçuk
Ahmet Selçuk 2022년 11월 1일
Thank you for your answer it saved me so much time.

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

추가 답변 (1개)

Daniel Shub
Daniel Shub 2012년 11월 20일
Assuming you mean the variable editor and not the workspace window, I think this is a possible bug. There seems to me no good reason to have the ability to sort by field, and not have it perform an alphabetical sort.
  댓글 수: 2
James
James 2016년 1월 5일
I don't think it is a bug... same issue here with MATLAB 2015a. Clicking on "Field" in the Variables window sorts the fields, but it appears to be a random sort; it is not alphabetical.
Walter Roberson
Walter Roberson 2016년 1월 6일
MATLAB structs are field order dependent.
A = struct('field1', [], 'field2', []);
B = struct('field2', [], 'field1', []);
A(2) = B;
Subscripted assignment between dissimilar structures.
However, [A;B] is fine

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

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by