Generate struct in matlab dynamically, with fields of different sizes

1

I'm a demand that the thing is, I want to create a set of images and I will list them, for this I create a struct vector similar to resultsInfo = struct('indice',0,'correlatas',cell(1,5),'fatorCorrelacao',zeros(1,5),'somaImagens',zeros(640,480)); % where: index is an integer representing the index of the image; correlates receives cell with 5 different names of images that are similar factorCorrelation is a vector that receives a number that represents how similar those images are; and somaImagens receives the sum of 5 similar images.

When I do that, it fills the headquarters of somaImagem field, only the first 5 elements of the vector, the other it allocates an empty array. My intention is to fill the vector dynamically, as the number of images may vary according to each project.

    
asked by anonymous 18.11.2015 / 19:35

1 answer

0

Answer at SOen

Define the following method:

function resultStruct = CreateEmptySruct ()
    resultStruct.img_index = 0  ;
    resultStruct.correlated  = cell(1,5);
    resultStruct.correlationFactor = zeros(1,5);
    resultStruct.ImgSum = zeros(640,480) ;
end

Then call this method in For loop like this:

for i = 1 :5
    structArray(i) = CreateEmptySruct () ;
end

However you can also set any value separately for each struct , passing function arguments.

    
20.11.2015 / 16:18