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

14 views (last 30 days)
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 Comments
Rik
Rik on 8 Apr 2021
It sounds like you should be using the parallel computing toolbox instead.
Raymond Norris
Raymond Norris on 8 Apr 2021
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.

Sign in to comment.

Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!