Skip to content

orderfields

miscellaneous · scripts/miscellaneous/orderfields.m

: s = orderfields (s1)
: s = orderfields (s1, s2)
: s = orderfields (s1, c)
: s = orderfields (s1, pv)
: [s, p] = orderfields (…)

Reorder the fields of the struct (array) s1.

Without a second argument the fields are sorted by name. The order can also be taken from another struct s2 with the same field names, from a cellstr c naming every field once, or from a permutation vector pv. The second output p is the permutation (a column) that was applied: p(i) is the old position of the new field i.