Clear Filters
Clear Filters

How to store results in a structure, by using parfor loop ?

17 views (last 30 days)
combinaison = struct();
parfor calcul = 1:2
coco = struct();
combinaison(calcul).modele = 5;
coco.modele.CL(1).branche(2).type = combinaison(calcul).modele;
disp(coco.modele.CL(1).branche(2).type);
end
Hi everyone,
I cannot store results in the "combination" structure for loop exit analysis...
Thank you in advance for your help !

Accepted Answer

Max Heimann
Max Heimann on 13 Jan 2022
Matlab does not support dynamically changing array sizes in parfor loops.
You need to preallocate your struct. Try this:
N = 2;
combinaison = repmat(struct(), N, 1 );
parfor calcul = 1:N
coco = struct();
combinaison(calcul).modele = 5;
coco.modele.CL(1).branche(2).type = combinaison(calcul).modele;
disp(coco.modele.CL(1).branche(2).type);
end

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!