Running multiple Matlab commands in only one terminal from command prompt
48 次查看(过去 30 天)
显示 更早的评论
Hello, everyone!
When we run a Matlab file from Windows command prompt, we generally use the following command line: (note the command is very simple, and it's just to illustrate the proceeding I am trying to develop)
matlab -nodesktop -r "a = 2"
Is there any way to, in another command through Windows command prompt, send a Matlab command (for example, fprintf('%d\n',a)) to the same terminal we've opened? Because if I type the following command:
matlab -nodesktop -r "fprintf('%d\n', a)"
it opens another terminal, just like the first one, and the variable a can't be read because there is no value associated to it !!
What I want to do is to send the fprintf command to the first Matlab terminal I've opened!
I hope my question is clear to everyone! =D
Thanks in advance!
0 个评论
回答(2 个)
Clayton Gotberg
2021-4-24
On Linux I'm able to do exactly what you want with the -nodesktop -nosplash -nojvm options - it takes over the terminal window to let me send commands as if it's the MATLAB command line - but it doesn't seem possible on Windows.
When I executed your first statement, it opened a MATLAB command line window. If you're already entering something via command prompt, is there any reason you're not switching the window? If you know what code you'll be running in advance, why not write a script to execute with the run command?
2 个评论
Clayton Gotberg
2021-4-26
Yes, your goal makes sense!
It sounds like you've written a batch file (or other command prompt script) to read in some value from the network, then pass it to MATLAB.
Does this trajectory analysis need to be in real-time? If not, just change the script to save the position value to a text file, then ask MATLAB to perform the analysis on that text file. You can read the contents of a text file with fscanf and a number of other functions.
If it needs to be in real-time, your current workflow of
- Read in data
- Call MATLAB to send it the value
- Repeat
is always going to have you wait 6-7 seconds between points, because MATLAB assumes you want to start a new instance as you have noted. Instead, try bringing the system commands into MATLAB! You can run them using the shell escape or the system function.
Walter Roberson
2021-4-26
MATLAB for Windows offers the Automation Server interface.
All MATLAB versions offer the Engine API so they can be called from other programs.
With Windows in particular, you may be able to use .NET System Diagnostic.Process to start MATLAB and connect other processes to input.
For Mac and Linux, you can create Named Pipes that look like files that you can read and write.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!