parfor Subscripted assignment dimension mismatch.
Show older comments
Hello!
i have a problem performing a long parfor...
i'm running it with a 4 core i7, and it seems that when a core finish its job it give me the Subscripted assignment dimension mismatch error becouse the error occour after it reach i = 1 (from the output i discovered that apparently it goes downward) i tried it with a simple for and it works perfectly, but since every iteraction need about 20sec and i need 256 iteraction (16 for testing) it take too much...
this is the code, thank you in advance for your help (i'm sorry for my english, i know it's bad)
parfor i = 1:16 %256
tic
for j = 1:256
%disp(j)
tmp = I1(i,j,:);
if tmp == 0
T2(i,j) = 0;
else
options = fitoptions('Method','NonlinearLeastSquares','Algorithm','trust-region','MaxFunEvals',5000,'MaxIter',2000);
options.StartPoint = [tmp(2),20,2]; % S0,T2*,C
options.Upper = [tmp(2)+100,70,10];
options.Lower = [0,0,0];
ffun = fittype('(S0.*exp(-t./T2))+C','coeff','S0','T2','C'},'independent','t','options',options);
[Sfit, G] = fit(TE1',reshape(tmp,10,1),ffun);
T2(i,j) = Sfit.T2;
err(i,j) = G.rmse;
end
end
toc
disp(i)
end
the output for this section is:
Elapsed time is 19.673806 seconds.
6
Elapsed time is 20.312663 seconds.
3
Elapsed time is 21.246476 seconds.
9
Elapsed time is 22.603829 seconds.
11
Elapsed time is 17.124702 seconds.
2
Elapsed time is 19.613248 seconds.
5
Elapsed time is 21.034833 seconds.
8
Elapsed time is 21.052930 seconds.
10
Elapsed time is 19.624255 seconds.
1
Subscripted assignment dimension mismatch.
Caused by:
Subscripted assignment dimension mismatch.
Accepted Answer
More Answers (1)
Walter Roberson
on 27 Jun 2013
I do not know if this will correct your difficulty, but I see a problem in your code.
tmp = I1(i,j,:);
if tmp == 0
We do not know the dimensions of I1, but it appears likely that I1(i,j,:) would have multiple elements and so that tmp would be a vector. Then in the "if" you compare that vector to 0, producing a vector of logical results, that is then evaluated by "if". When "if" is applied to a vector or matrix, then the condition is only considered to be true if all elements of the vector or matrix are true -- so the "if" would only be true if I1(i,j,:) are all 0. Is that what you want? If it is, then it is best to code that meaning for clarity, using
if all(tmp == 0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!