How to Use MATLAB 'system' Function to Open Multiple Terminals?

AI Thread Summary
The discussion focuses on using MATLAB's 'system' function to open multiple MATLAB terminals and execute a custom function with variable inputs. The initial attempts resulted in errors related to undefined variables. After several trials, a successful solution was found by constructing a command string that converts variables to strings using 'num2str' before passing them to the 'system' function. The final working command is formatted to include the necessary variable values correctly. This method allows for the successful execution of the desired function across multiple terminals.
GreenLRan
Messages
59
Reaction score
0
Hi,
I need to call the system function to open up several other MATLAB terminals and call a function I wrote that will have variable input. I have tried a lot of different methods but to no avail. This is basically what I'm trying to do.


for i = 1:numberOfTerminals

system('C:\MATLAB\R2009b\bin\matlab -r myFunction(var1*i,var2)')

end

I get errors saying the variables are undefined.

I have tried

...

system(['C:\MATLAB\R2009b\bin\matlab -r myFunction(', var1*i, var2, ')' ]);

and

system(['C:\MATLAB\R2009b\bin\matlab -r myFunction(%var1*i%,%var2%)' ]);

etc...

Thanks for the help!
 
Physics news on Phys.org
I solved it myself.

For those interested, it can be done..

str = ['C:\MATLAB\R2009b\bin\matlab -r Func(', num2str(var1), ',' ,num2str(var2) ',',num2str(var3), ')'];

system(str)
 
Back
Top