Reputation: 300
All,
I met a very interesting situation on my parfor run on matlab, and following is my question.
fid = 'test.nc';
temp = ncread(fid,'temp');
[s1,s2,s3] = size(temp);
for m = 1 : 100
parfor xid = 1 : s1
for yid = 1 : s2
output = struct;
output.t = squeeze(temp(xid,yid,:));
if ~isnan(temp(xid,yid,37))
output.t(:) = 1;
else
output.t(:) = nan;
end
temp(xid,yid,:) = output.t;
end
end
end
In this case, I got the error message...
"Error using pwp_parallel (line 238) Error: The variable temp in a parfor cannot be classified.See Parallel for Loops in MATLAB, "Overview"."
However, if my code is looking like this...
fid = 'test.nc';
temp = ncread(fid,'temp');
[s1,s2,s3] = size(temp);
for m = 1 : 100
parfor xid = 1 : s1
for yid = 1 : s2
output = struct;
output.t = squeeze(temp(xid,yid,:));
output.t(:) = 1;
temp(xid,yid,:) = output.t;
end
end
end
The code is running.
Could someone help me to deal with this error?
Upvotes: 0
Views: 94
Reputation: 300
I figured it out by myself after I posted it lol
The question now is the if condition within the parfor doesn't recognize what the variable temp is. However, the if condition does recognize the variable output.t.
So, in this case, I just need to replace the variable "temp(xid,yid,37)" in the if condition by "output.t(37)", then the question is solved.
Upvotes: 0