How do I run Multiple Scripts at the same time automatically?

조회 수: 14 (최근 30일)
Scott Ziegler
Scott Ziegler 2021년 4월 8일
댓글: Raymond Norris 2021년 4월 8일
I have a script that runs continuously throughout the day, every day. It analyzes live data and has to much data to be able to handle it on its own. So I've broken the data set down into 40 pieces, and open 40 instances of MATLAB and run a slightly different script for each piece of the data. The scripts have been setup to handle the variable changes automatically. I'm struggling to figure out how to automatically open those 40 instances of MATLAB and get it running automatically.
I've tried the below code(s) to try and open it from the command line and start. For the second line I've varied it to include the path or not, and tried with and without try. Unfortunately MATLAB opens, but it runs the last script selected in a previous instance.
matlab -nosplash -nodesktop -r 'Pattern_2_Num_21'
matlab.exe -r "cd C:\Users\scott\Documents; try, run ('C:\Users\scott\Documents\Pattern_2_Num_21.m'); end"
I've also tried the below code in MATLAB, it also opens a new instance of MATLAB. The first one just shows the name of the script in the command line, then enters waiting for another command. The second runs something, the first thing my code does is output the file name, which is the last script used (not the one I want), then in workspace the variables it populates appear to be correct, but editor does not show the script. This won't work since it doesn't have the right script appearing in the file name lookup.
!matlab -r disp('Pattern_2_Num_1') &
!matlab -r run('Pattern_2_Num_2') &
Code to get file name:
The_File_Name = matlab.desktop.editor.getActiveFilename
The_File_Name_1 = erase(The_File_Name,'C:\Users\scott\Documents\Pattern_2_Num_');
The_File_Name_2 = erase(The_File_Name_1,'.m');
The_File_Name_3=str2double(The_File_Name_2);
App_Number=The_File_Name_3;
  댓글 수: 2
Rik
Rik 2021년 4월 8일
It sounds like you should be using the parallel computing toolbox instead.
Raymond Norris
Raymond Norris 2021년 4월 8일
Agreed, I think Parallel Computing Toolbox is the right option.
It sounds like you load a file, then query the Editor for the name, strip out the App number, and then run it?
From the main MATLAB session, could you run a loop of batch jobs?
scripts = {'Pattern_2_Num_11','Pattern_2_Num_12','Pattern_2_Num_21','Pattern_2_Num_22'};
for sidx = 1:numel(scripts)
j(sidx) = batch(scripts{sidx});
end
The call to batch might need a bit tweaking. But then you can quit your main MATLAB session.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by