0

I wounder what is the most efficient way to run a program, given as executable, from Matlab many times in a for loop. At the moment I use the following Code:

for i = 1:100
    system('MyProgram.exe');
    % Do something with the output from the .exe
end

So, from the profiler I know that 99,9% of the time is used in the execution of the Program itself. My question is basically if there is a more efficient way to run executables in general from within Matlab?

I have read that everytime I run an exe like described above, a process is created which has to initialize the Matlab runtime environment... Is there possibly a way to avoid this by only doing the initialization once and from there on run the programm multiple times?

SampleTime
  • 291
  • 3
  • 19

1 Answers1

0

I am guessing your can't directly modify the .exe's you are given, so perhaps there is a way to instead of calling the .exe directly, you could call a .bash shell script.

I would imagine that if you do this and within the shell script check to see if a workspace is already open to associate the execution of the .exe with a specific process ID. Although I would guess that when the executable finishes it closes the session.

Just throwing some stuff out there :P I have had lots of trouble with how Matlab handles this kind of thing (Also things like Excel).

Hope you figure this out.

EDIT: I found some possible examples here Example Descriptions

-Kyle

Community
  • 1
  • 1
Kyle Pastor
  • 489
  • 4
  • 8