You are now following this Submission
- You will see updates in your followed content feed
- You may receive emails, depending on your communication preferences
The code takes in a structure and a field name it is looking for. It will then recursively search through the structure for the given field name and add the value to a cell array of dimensions nxn1xn2... where n is the maximum number of records on the first layer of the structure, n1 is the maximum on the second etc.
eg.
bob(1).fred(1).mike(1).name='oneoneone';
bob(1).fred(1).mike(2).name='oneonetwo';
bob(1).fred(1).mike(3).name='oneonethree';
bob(1).fred(2).mike(1).name='onetwoone';
bob(1).fred(2).mike(2).name='onetwotwo';
bob(2).fred(1).mike(1).name='twooneone';
bob(2).fred(1).mike(2).name='twoonetwo';
bob(2).fred(2).mike(1).name='twotwoone';
bob(2).fred(2).mike(2).name='twotwotwo';
bob(1).george(1).fed='boo';
bob(1).george(2).fed='awk';
ret=collapseStructure(bob,'name');
ret(:,:,1) =
'oneoneone' 'onetwoone'
'twooneone' 'twotwoone'
ret(:,:,2) =
'oneonetwo' 'onetwotwo'
'twoonetwo' 'twotwotwo'
ret(:,:,3) =
'oneonethree' []
[] []
credit to Jos (10584) for help/writing padCell.m
Cite As
Caradoc (2026). collapseStructure (https://www.mathworks.com/matlabcentral/fileexchange/26347-collapsestructure), MATLAB Central File Exchange. Retrieved .
General Information
- Version 1.2.0.0 (2.54 KB)
MATLAB Release Compatibility
- Compatible with any release
Platform Compatibility
- Windows
- macOS
- Linux
