Extract variable from function after using parfeval

2 ビュー (過去 30 日間)
Koren Murphy
Koren Murphy 2022 年 8 月 12 日
コメント済み: Raymond Norris 2022 年 8 月 16 日
I am running the following:
fcn=@(i) run("test"+i);
for K=1:4
F(K)=parfeval(fcn,0,K);
end;
where "test"+i is a script solving to pricude results in matrix format.
I would like to be able to see this matrix after the worker has finished.
I have tried setting the cript as a fucntion and having an outout:
function [Result1]= test1
however I still get no data out of this after using fetchOutputs.
How can i get the variable I require after parfeval has finished?
  2 件のコメント
Koren Murphy
Koren Murphy 2022 年 8 月 12 日
Yes it has

サインインしてコメントする。

回答 (1 件)

Raymond Norris
Raymond Norris 2022 年 8 月 12 日
@Koren Murphy the issue is that you've told MATLAB there are no output arguments (even if there are)
F(K)=parfeval(fcn,0,K);
The "0" is the number of output arguments. Change this appropriately. For instance
for idx = 1:10
f(idx) = parfeval(@rand,1,idx);
end
% Now fetch the results
for idx = 1:10
[idx, value] = fetchNext(f);
R{idx} = value;
end
  2 件のコメント
Raymond Norris
Raymond Norris 2022 年 8 月 16 日
The run command doesn't return any outputs. Presumable this is a test example. Replace it with the function you're going to actually run.

サインインしてコメントする。

カテゴリ

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by