Variable not found in parfor loop
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
Walter Roberson
2017 年 1 月 20 日
Which MATLAB version?
My spidy-senses are suggesting you might be using R2015b or R2016a but not R2016b ?
採用された回答
Walter Roberson
2017 年 1 月 20 日
You do not initialize the variable in the zfun loop.
5 件のコメント
Walter Roberson
2017 年 1 月 21 日
Yes, that would have less overhead. However, due to finite precision of floating point numbers, the result of the above is going to be -inf below about -1/17 and +inf above it. The zero is at about -0.058197670686932642438500200510901 . If you were trying to find the zero, it would be much more effective to use the symbolic toolbox.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!