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

查看:217
本文介绍了运行使用多个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.

推荐答案

首先必须找到一种以编程方式打开会话的方法. 基于

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天全站免登陆