运行使用多个 MATLAB 会话的脚本 [英] Run a script that uses multiple MATLAB sessions

查看:75
本文介绍了运行使用多个 MATLAB 会话的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在多个 MATLAB 会话中自动调用具有简单输入的函数?

How to call a function with simple inputs in several MATLAB sessions automatically?

手动方法是:

  • 打开三个会话
  • 调用magic(t),其中t分别为1、2或3
  • Open three sessions
  • Call magic(t) where t is 1, 2 or 3 respectively

所以,我的问题是:我怎样才能以编程方式完成这一切?

So, my question is: How can I do this all programatically?

如果相关,我不想使用并行处理工具箱.

In case it is relevant, I do not want to use the parallel processing toolbox.

请注意,我不认为 parfor 循环可以做我想做的事.首先,这需要并行处理工具箱,其次我希望能够在其中一个操作失败时立即进行调试,而不会打扰其他会话.

Note that I don't think a parfor loop can do what I want. First of all that would require the parallel processing toolbox, and secondly I want to be able to debug as soon as one of these operations fails, without bothering the other sessions.

推荐答案

首先必须找到以编程方式打开会话的方法.基于 thisthis 发现您可以按如下方式执行(也适用于 Windows):

First of all a way must be found to open sessions programatically. Based on this and this it is found you can do it as follows (works on windows as well):

% Opening 3 matlab sessions
for t = 1:3
!matlab &
end

除了简单的打开之外,还可以给出一个简单的命令

Besides simply opening them, a simple command can also be given

!matlab -r "magic(5)" &

现在,要最终结合起来,只剩下一个小技巧:

Now, to finally combine this just a small trick remains:

for t = 1:3
   str = ['!matlab -r "magic(' num2str(t) ')" &'];
   eval(str)
end

请注意,如果您想使用更复杂的输入,您可以简单地将它们保存在一个结构中,并通过使用包装脚本作为被调用函数来使用此索引调用它们.

Note that if you want to use more complicated inputs you can simply save them in a struct and call them with this index by using a wrapper script as called function.

这篇关于运行使用多个 MATLAB 会话的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆