本文介绍了是否可以通过编程方式打开/关闭Matlab PARFOR循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MATLAB中有一个关于parfor的简单问题.我想在程序中设置一个标志,以在parfor和常规for循环之间进行更改.基本上,我需要此功能,以便我的代码的某些部分可以在调试"模式下更新图形,然后在关闭标志时,使用不进行图形更新的parfor来提高速度.

Have a simple question about parfor in MATLAB. I would like to set a flag in my program to change between parfor and regular for loops. Basically, I need this functionality so that some parts of my code can update graphics in a "debug" mode, then when the flag is turned off, use parfor with no graphics updates for speed.

因此,我正在寻找具有此功能的简单物品:

So, I'm looking for something simple that has this functionality:

if (flag)
  for i = 1:n
else
  parfor i = 1:n
end

  % Do loop tasks.

  end

任何帮助将不胜感激!谢谢!

Any help would be greatly appreciated! Thanks!

推荐答案

另一个选项-使用 PARFOR

if flag
  arg = Inf;
else
  arg = 0;
end
parfor (idx = 1:n, arg)
   ...
end

这篇关于是否可以通过编程方式打开/关闭Matlab PARFOR循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:22