%% Reorder Using Permutation Vector from Another Structure
% Create a structure.

data1.x = linspace(0,2*pi);
data1.y = sin(data1.x);
data1.title = 'y = sin(x)';

%
% Reorder the structure using the orderfields function. Store the new field order in a permutation vector Pout.

[S,Pout] = orderfields(data1,{'title','x','y'})

%
% Create a second structure with the same fields.

data2.x = data1.x;
data2.y = cos(data2.x);
data2.title = 'y = cos(x)';

%
% Reorder the fields of data2 using Pout. If you have many structures with the same field names, then you can use Pout to reorder them all in the same way.

S2 = orderfields(data2,Pout)

% Copyright 2018 The MathWorks, Inc.