groupStruct

Group a struct-array by the nominal values for specified fields.
165 Downloads
Updated 29 May 2012

View License

Group a struct-array by the nominal values (which will be created) for the fields you specify. Returns a grouped struct, a cell-array containing the different groups, a cell-array with the nominal values that were used, a cell-array with the fields that were used, and a cell-array with the indexes from the original struct corresponding to the one used in the groups.
If you for instance have a struct-array with experimental data with different inclinations (PHI) and velocities (V) you can use the following example to group the experiments by the nominal values for the fields PHI and V:

%Create some artificial experimental data
s=struct;
s.PHI=0;
s.V=1.1;
s(end+1).PHI=1;
s(end).V=1.082;
s(end+1).PHI=0;
s(end).V=1.084;
s(end+1).PHI=1;
s(end).V=0.61;
s(end+1).PHI=1;
s(end).V=0.58;
s(end+1).PHI=0;
s(end).V=0.598;
s(end+1).PHI=0;
s(end).V=1.12;

%Group the struct by PHI and V, using 5% as tolerance when creating nominal values for both PHI and V.
[sOut,groups,nomsOut,ids,inds] = groupStruct( s, {'PHI','V'}, [0.05,0.05] );

Requires the 'nominal' function, and the 'getarg' function.

Cite As

Ivar Eskerud Smith (2024). groupStruct (https://www.mathworks.com/matlabcentral/fileexchange/36897-groupstruct), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Structures in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0