Making array of structure
Post date: Aug 31, 2011 1:30:54 PM
Approach I: Making an empty array of structure
- Make an array of structure:
- sa = struct('image',{}, 'N_pixel',{}, 'imagename',{});
- Replicate the structure array
- SA = repmat(sa,[10 5]);
Approach II: is to first make a cell array, then convert to array structure
- Make a cell array
- fieldName = ('image', 'N_pixel', 'imagename');
- N_ROW = 10; N_COL = 5;
- sa = cell(N_ROW, N_COL, 3); % 3 here is the number of fields name
- Convert the cell array to structure
- SA = cell2struct(sa, fieldName, 3); % 3 here is the dim=3 of the cell array
- for more information, visit MATLAB page.
Note: Reportedly, structure array is slower than using cell array and can potentially break when running in parallel mode.