I made simple code to test for saving struct variable in parfor loop.
parfor k=1:3 my_field = sprintf('v%d', k); variable.(my_field) = k*2;end
But, i did not get the results I wanted, and there was only a variable with an empty value in the workspace.
If I use for instead of parfor, I get the result I want perfectly. However, the function(not the simple like above code) actually used takes a long time, so I want to use parfor.
How do I save a struct variable such as variable.v1, variable.v2 in a struct variable using parfor?
Best Answer