Effacer les filtres
Effacer les filtres

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

30 vues (au cours des 30 derniers jours)
Michael cohen
Michael cohen le 13 Jan 2022
Commenté : Michael cohen le 13 Jan 2022
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 !

Réponse acceptée

Max Heimann
Max Heimann le 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

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by