Run a script that uses multiple MATLAB sessions

后端 未结 2 966
孤街浪徒
孤街浪徒 2020-11-29 09:38

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

The manual way to do it would be:

  • Open three sessions
  • Call
相关标签:
2条回答
  • 2020-11-29 10:21

    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.

    0 讨论(0)
  • 2020-11-29 10:24

    You could try Multicore, which uses several instances of Matlab to do what parfor does by passing information via a common directory. If you can rewrite your code loop to call a function that returns values then Multicore might do what you are looking for.

    http://www.mathworks.com/matlabcentral/fileexchange/13775-multicore-parallel-processing-on-multiple-cores

    0 讨论(0)
提交回复
热议问题