1

I would like to push a field before another one in a struct. I coulnd't find any functions with Matlab help. Is there an easy and efficient way to implement this? Do I have to shift all the struct fields when I insert a new one 'before an other field'?

Example:

a=struct;
a.b='2';
a.c='3';
a.bb='2.5';
a %displays the struct fields and sequence
Adiel
  • 3,071
  • 15
  • 21
user2305193
  • 2,079
  • 18
  • 39

1 Answers1

-2
s = struct('b',2,'c',3,'a',1):
snew = orderfields(s);

Reference: https://mathworks.com/help/matlab/ref/orderfields.html

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98