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

Click For Summary
SUMMARY

The discussion focuses on using the MATLAB 'system' function to open multiple MATLAB terminals and execute a user-defined function with variable inputs. The user initially encountered errors related to undefined variables when attempting to pass variables directly into the system command. The solution involved constructing a command string using 'num2str' to convert variables into a string format that MATLAB can interpret correctly. The final working command is: system(str), where str is constructed with the appropriate variable values.

PREREQUISITES
  • Familiarity with MATLAB R2009b syntax and functions
  • Understanding of the 'system' function in MATLAB
  • Knowledge of string manipulation in MATLAB
  • Basic programming concepts, particularly loops
NEXT STEPS
  • Explore advanced string manipulation techniques in MATLAB
  • Learn about MATLAB's 'eval' function for dynamic command execution
  • Investigate parallel computing options in MATLAB for handling multiple processes
  • Study error handling in MATLAB to manage undefined variables effectively
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those interested in automating tasks across multiple instances of MATLAB, as well as developers looking to enhance their scripting and function execution skills within MATLAB environments.

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)
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 10 ·
Replies
10
Views
3K
Replies
4
Views
6K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
2K