How to use parfor?
Afficher commentaires plus anciens
Hi, i'm trying to use par-for in this code, but it matlab gives me this error: "Error: The variable D in a parfor cannot be classified.
See Parallel for Loops in MATLAB, "Overview"."
Anybody can explain me how does parfor works and how to modify this for properly?
clear; close all;
load('data_c2')
tic
% datas= Crosscurv,Elevation,Flowacc,Longcurv,Slope,Rv_mean,Rv_range_interq,Rv_median,Zero
D = [data_c2(:,2),data_c2(:,9),data_c2(:,5),data_c2(:,4),data_c2(:,7),data_c2(:,1),data_c2(:,3),data_c2(:,8)];
%D = Elevation, Zero, Slope, Longcurv, Rv_range_interq, Crosscurv, Flowacc, Rv_median
D(D == -9999) = NaN;
elevMax = max(D(:,1));
slopeMax = max(D(:,3));
longcurvMax = max(D(:,4));
crosscurvMax = max(D(:,6));
flowaccMax = max(D(:,7));
elevMin = min(D(:,1));
slopeMin = min(D(:,3));
longcurvMin = min(D(:,4));
crosscurvMin = min(D(:,6));
flowaccMin = min(D(:,7));
ticBytes(gcp);
PCtime = clock;
Date = strcat(num2str(PCtime(1)),'/',num2str(PCtime(2)),'/',...
num2str(PCtime(3)),'-',num2str(PCtime(4)),':',...
num2str(PCtime(5)));
text = ['Inizio loop ',' - ',Date];
disp(text)
parfor j= (1:length(D))
%max
if D(j,1) == elevMax;
D(j,1) = (elevMax - 1);
end
if D(j,3) == slopeMax;
D(j,3) = (slopeMax - 1);
end
if D(j,4) == longcurvMax;
D(j,4) = (longcurvMax - 1);
end
if D(j,6) == crosscurvMax;
D(j,6) = (crosscurvMax - 1);
end
if D(j,7) == flowaccMax;
D(j,7) = (flowaccMax - 1);
end
%min
if D(j,1) == elevMin;
D(j,1) = (elevMin + 0.1);
end
if D(j,3) == slopeMin;
D(j,3) = (slopeMin + 0.1);
end
if D(j,4) == longcurvMin;
D(j,4) = (longcurvMin + 0.1);
end
if D(j,6) == crosscurvMin;
D(j,6) = (crosscurvMin + 0.1);
end
if D(j,7) == flowaccMin;
D(j,7) = (flowaccMax + 0.1);
end
end
tocBytes(gcp)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!