Info

This question is closed. Reopen it to edit or answer.

Problem indexing in parfor

5 views (last 30 days)
Juan Young
Juan Young on 6 Nov 2016
Closed: MATLAB Answer Bot on 20 Aug 2021
Hello, I have a program (an Ising model) which I must make it evolve until certain state, and then start to save the data in an array. But as im using parfor, I cant use the normal way of indexing. The code is something like this:
parfor T=1:nT
for i=1:tfinal
f=Function(f,parameters);
if i> (tfinal-tdat)
j=j+1 <--------------------------------Here is the problem
MdeT(T,j)=sum(sum(L));
EdeT(T,j)=E;
end
end
end
Thats how I want it to work, but I CANT use the "j" cumulative parameter inside the "MdeT", array in which I want to gather the information. How can I possibly do to save the information past a certain point, and not since the beginning, in a parfor?

Answers (1)

Walter Roberson
Walter Roberson on 7 Nov 2016
You cannot.
However, you can save to cell arrays or structs with consistent indexing and with empty contents. Or you could,
MdeT(T, j - (tfinal - tdat)) = sum(sum(L));
EdeT(T, j - (tfinal - tdat)) = E;

This question is closed.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!