Function with multiple output within a parfor loop giving assigment mismatch error
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I was wondering if someone could help with the following. I have the following code below, which runs fine using a parfor loop.
ImpedanceMat_Wind = ones(size(LatMat,1),size(LatMat,2),size(Adjacency,3),...
length(FL),length(timeofday)) * Inf;
TempMat_Wind = ones(size(LatMat,1),size(LatMat,2),size(Adjacency,3),...
length(FL),length(timeofday)) * Inf;
DistanceMat = ones(size(LatMat,1),size(LatMat,2),size(Adjacency,3)) * Inf;
for ii=1:size(LatMat,1)
for jj=1:size(LatMat,2)
parfor kk=1:size(Adjacency,3)
if (Adjacency(ii,jj,kk) ~= -999)
row = floor(Adjacency(ii,jj,kk)/(size(LatMat,2)));
if (rem(Adjacency(ii,jj,kk),size(LatMat,2)) > 0)
row = row + 1;
end
col = rem(Adjacency(ii,jj,kk),size(LatMat,2));
if (col == 0)
col = size(LatMat,2);
end
ImpedanceMat_Wind(ii,jj,kk,:,:) = CalculateImpedance4D(LatMat,...
LonMat,ii,jj,row,col,UwndMat,VwndMat,TempMat,...
mach_number,FL,timeofday);
[DistanceMat(ii,jj,kk),~] = distance('rh',LatMat(ii,jj),...
LonMat(ii,jj),LatMat(row,col),LonMat(row,col));
end
end
end
end
I then modified the function 'CalculateImpedance' so that it will produce two outputs and rewrite the above code as
ImpedanceMat_Wind = ones(size(LatMat,1),size(LatMat,2),size(Adjacency,3),... length(FL),length(timeofday)) * Inf; TempMat_Wind = ones(size(LatMat,1),size(LatMat,2),size(Adjacency,3),... length(FL),length(timeofday)) * Inf; DistanceMat = ones(size(LatMat,1),size(LatMat,2),size(Adjacency,3)) * Inf;
for ii=1:size(LatMat,1)
for jj=1:size(LatMat,2)
parfor kk=1:size(Adjacency,3)
if (Adjacency(ii,jj,kk) ~= -999)
row = floor(Adjacency(ii,jj,kk)/(size(LatMat,2)));
if (rem(Adjacency(ii,jj,kk),size(LatMat,2)) > 0)
row = row + 1;
end
col = rem(Adjacency(ii,jj,kk),size(LatMat,2));
if (col == 0)
col = size(LatMat,2);
end
[ImpedanceMat_Wind(ii,jj,kk,:,:),TempMat_Wind(ii,jj,kk,:,:)] =
CalculateImpedance4D(LatMat,...
LonMat,ii,jj,row,col,UwndMat,VwndMat,TempMat,...
mach_number,FL,timeofday);
[DistanceMat(ii,jj,kk),~] = distance('rh',LatMat(ii,jj),...
LonMat(ii,jj),LatMat(row,col),LonMat(row,col));
end
end
end
end
and this gives a subscripted assignment dimension mismatch error at line 34, which corresponds to the line 'parfor kk=1:size(Adjacency,3)'. I'm really confused because the second output is pre-allocated and has exactly the same shape as the first. It's only when I direct the function to also accept the second output that I get this error. Any help would be greatly appreciated. Thanks!
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!