Variable not found in parfor loop

9 views (last 30 days)
JohnDylon
JohnDylon on 20 Jan 2017
Commented: JohnDylon on 22 Jan 2017
If I run the script:
z=1:1000;
parfor i=1:numel(z)
zfun(z(i))
end
which calls the function:
function zfun(z)
for j=1:50
for k=1:100
myz=z*10+myz*k;
end
end
save(fullfile('filepath', num2str(myz)), 'myz');
end
I get an error of Undefined function or variable 'myz' for the save command.
Any ideas how to fix this?
  2 Comments
JohnDylon
JohnDylon on 20 Jan 2017
R2016b trial for Linux. (No error for 2014a on PC though!)

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 20 Jan 2017
You do not initialize the variable in the zfun loop.
  5 Comments
JohnDylon
JohnDylon on 22 Jan 2017
Thank you for all valuable guidance.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by