Removing clear all from your code and loading to a struct (instead of poofing variables into existence) should allow you to replace the outer for loop by a parfor. Don't forget to preallocate your variables in the loop, instead of implicitly setting them to empty arrays with clear.
Parallel for loop in loading files
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I would like to make the following code in parallel. Could you please help me?
clear all; clc;
for kk= 1:30014
m = 0; n = 0;
for j = 1:5
load(['File' num2str(kk) '_' num2str(j) '.mat']);
iteration(j) = iter;
FScore(j) = score;
NDistance(j)= distance;
allF(j,:) = F;
if FScore(j) < 0
m = m+1;
negF(m,:) = F;
negFScore(m) = score;
negDistance(m) = distance;
else
n =n+1;
posF(n,:) = F;
posFScore(n) = score;
posDistance(n) = distance;
end
end
[minFScore,minFScoreIndex] = min(FScore);
[minDistance, minDistanceIndex] = min(NDistance);
if minFScore < 0
[minNegFScore,minNegFScoreIndex] = min(negFScore);
[minNegDistance, minNegDistanceIndex] = min(negDistance);
allFVoilatingH = negH(minNegFScoreIndex,:);
allFVoilatingAndMinDistH = negH(minNegDistanceIndex,:);
filename = ['nv_' num2str(kk) '.mat'];
save(filename,'negDistance','allFVoilatingH', 'allFVoilatingAndMinDistH', 'minDistance','minNegFScore','minNegFScoreIndex','minNegDistance','minNegDistanceIndex','minDistanceIndex','allF','normDistance','negFScore','negH', 'minFScore','minFScoreIndex', 'FScore', 'iteration');
else
filename = ['pv_' num2str(kk) '.mat'];
save(filename, 'allF','NDistance','minFScore','minFScoreIndex', 'FScore', 'iteration');
end
clear all; clc;
end
Thanks in advance.
0 commentaires
Réponses (1)
Voir également
Catégories
En savoir plus sur Numeric Types 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!