Making array of structure

Post date: Aug 31, 2011 1:30:54 PM

Approach I: Making an empty array of structure

  1. Make an array of structure:
    1. sa = struct('image',{}, 'N_pixel',{}, 'imagename',{});
  2. Replicate the structure array
    1. SA = repmat(sa,[10 5]);

Approach II: is to first make a cell array, then convert to array structure

  1. Make a cell array
    1. fieldName = ('image', 'N_pixel', 'imagename');
    2. N_ROW = 10; N_COL = 5;
    3. sa = cell(N_ROW, N_COL, 3); % 3 here is the number of fields name
  2. Convert the cell array to structure
    1. SA = cell2struct(sa, fieldName, 3); % 3 here is the dim=3 of the cell array
    2. 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.