Replacing "test(ii,1)=Test(input,ii);" with "test{ii}=Test(input,ii);" also appears to prevent the error from occuring.
What is causing this intermittent error in parfor?
36 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Chris
le 8 Déc 2025 à 21:59
Modifié(e) : Matt J
le 9 Déc 2025 à 13:04
The attached script produces an intermittent error:

Increasing n in untitled_script.m appears to increase the likelihood of the error occuring. Replacing parfor with for prevents the error from occuring. Setting n=1 prevents the error from occuring. Replacing "test(ii,1)=Test(input,ii);" with "Test(input,ii);" prevents the error from occuring.
Anyone understand what is going on here?
Réponse acceptée
Matt J
le 9 Déc 2025 à 0:56
Modifié(e) : Matt J
le 9 Déc 2025 à 1:04
If you add the indicated line, your class constructor will support no-argument calls, and the error will go away:
function obj = Test(inputArg1,ii)
arguments
inputArg1
ii = 2
end
if ~nargin, return; end %<---- Add this
display(num2str(ii))
obj = obj.method1(inputArg1);
end
This is necessary because the loop variable values ii in a parfor loop will not be visited in in sequential order, meaning that certain elements in the vector test will need to be populated temporarily with argument-free constructor calls.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!