<< num2cell | Data structures | rmfield >> |
S = orderfields(S1) |
S = orderfields(S1, S2) |
S = orderfields(S1, C) |
S = orderfields(S1, P) |
[S, Pout] = orderfields(...) |
structure array: Input structure.
structure array: Field order by structure.
cell array of character vectors or string array: Field order by name
numeric vector: Field order by number.
structure array: Reordered structure.
numeric vector: Output field order.
S = orderfields(S1) sorts the fields in S1 alphabetically by their names, considering uppercase letters before lowercase ones, and digits and underscores are also accounted for.
S = orderfields(S1,S2) returns a copy of S1 with its fields rearranged to match the order of fields in S2.Both S1 and S2 must share the same field names.
S = orderfields(S1, C) matches the order specified in the input array C. Each field name from S1 must appear once in C.
S = orderfields(S1, P) reorders fields based on the permutation vector P. P contains integers from 1 to n, where n is the number of fields in S1. This syntax is useful for maintaining consistent ordering across multiple structure arrays.
[S, Pout] = orderfields(...) also returns a permutation vector Pout, indicating the changes in field order. Pout consists of integers from 1 to n, reflecting the rearranged field positions. This syntax is compatible with any of the previously mentioned arguments.
orderfields function exclusively arranges the top-level fields and doesn't operate recursively.
s = struct ("d", 4, "b", 2, "a", 1, "c", 3);
tA = orderfields (s)
t = struct ("d", {}, "c", {}, "b", {}, "a", {});
tB = orderfields (s, tA)
Version | Description |
---|---|
1.5.0 | initial version |
Allan CORNET