Batch Processing of a Function with Different Arguments

1 回表示 (過去 30 日間)
David C
David C 2014 年 10 月 13 日
コメント済み: David C 2014 年 10 月 16 日
Hello,
I read the documentation on batch and diary functions, but I could not find the answer. I have a function, longjob(n), which needs to be run for many n values, which are recorded in nVector. I would like to record the output to the screen for each run.
Right now, I'm typing many lines:
someJob1=batch('longjob',1,{nVector(1)})
someJob2=batch('longjob',1,{nVector(2)})
someJob3=batch('longjob',1,{nVector(3)})
...
diary(someJob1) >> job1out.txt
diary(someJob2) >> job2out.txt
diary(someJob3) >> job3out.txt
...
Question: How do I put this in a for loop without using eval? I am not sure how to create a job vector.
Thanks.

採用された回答

Thomas Ibbotson
Thomas Ibbotson 2014 年 10 月 14 日
I think code that looks something like this will work:
for jobIdx = 1:length(nVector)
jobs(jobIdx) = batch('longjob', 1, {nVector(jobIdx)});
end
for jobIdx = 1:length(jobs)
% Wait for the job to finish running before getting its output
wait(jobs(jobIdx));
diary(jobs(jobIdx), ['job' num2str(jobIdx) 'out.txt']);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by