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

In summary, the individual is seeking help with using the system function in MATLAB to open multiple terminals and call a function with variable inputs. They have tried various methods but encountered errors with undefined variables. They eventually solved the issue by using a string with the correct format for the system function.
  • #1
GreenLRan
61
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
  • #2
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)
 

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

What is the purpose of the 'system' function in MATLAB?

The 'system' function in MATLAB is used to execute system commands or launch applications from within MATLAB. It allows the user to interact with their operating system and perform tasks such as file operations, running external programs, and managing processes.

How do I use the 'system' function to run an external program?

To use the 'system' function to run an external program, you need to specify the name of the program as the input argument. You can also include additional arguments or options as needed. For example, to run a program called "myprogram.exe", you would use the command "system('myprogram.exe')".

Can I capture the output of the 'system' function in MATLAB?

Yes, the 'system' function allows you to capture the output of the external program or system command that is executed. You can use the syntax [status, output] = system(...) to store the output in a variable named 'output'. The 'status' variable will indicate whether the command was executed successfully.

How do I run a system command with administrator privileges using the 'system' function?

To run a system command with administrator privileges, you can use the 'system' function with the 'runas' option. For example, to run the command "netsh wlan show profile" as an administrator, you would use the command "system('runas netsh wlan show profile')". This will prompt the user for administrator credentials.

Can I use the 'system' function to open a file in an external program?

Yes, the 'system' function can be used to open a file in an external program. You can specify the name of the program followed by the file path as the input argument. For example, to open a file called "mytextfile.txt" in Notepad, you would use the command "system('notepad mytextfile.txt')".

Back
Top