call and run an external program in matlab under windows

135 ビュー (過去 30 日間)
Cenk OZAN
Cenk OZAN 2011 年 7 月 13 日
コメント済み: Hunter Pruett 2022 年 7 月 20 日
Does anybody have any idea about how to call and run an external program in matlab under windows? I want to call an external program in Matlab and this external program should read its input file in Matlab directory and then this external program should create the program's output file in Matlab directory.

回答 (5 件)

Rick Rosson
Rick Rosson 2011 年 7 月 13 日
You can call an executable program from the command line using the exclamation point or the system command:
>> !hello
will cause Windows to execute the program hello.exe if there is such a file in the current directory or on the system path.
Alternatively:
>> system('hello');
will do the same thing.
HTH.
  3 件のコメント
Chirag Gupta
Chirag Gupta 2011 年 7 月 13 日
This really depends on you external program. If your external program takes the input file name as an argument, you should be able to do:
!myExternalProgram inputFile.txt
However, if your external program does not take input arguments, you basically have to provide an inetrface where 2 external applications can talk together (non trivial)
Ahmed Abed
Ahmed Abed 2017 年 6 月 15 日
I have been in the same situation, you can try the following code: system('C:\folder\programme.exe C:\folder\file same.DAT'); this is just an example, you need to enter the path of your programme then the path of the file to be analised. this way worked fine with me, however, if the external programme needs a human interference after finishing the analysis, then you need to manually close the programme so you can complete your code, and this is exactly where I am stuck currently.

サインインしてコメントする。


Aleksander
Aleksander 2013 年 5 月 13 日
Would it be possible to launch an program from matlab code without keeping in the matlab program. my issue is that when i launch it this way matlab will wait for the external program to close before it continues.
  2 件のコメント
Kaustubha Govind
Kaustubha Govind 2013 年 5 月 13 日
Aleksander: If you're on Linux, I think adding an ampersand (&) to the end of your command should do what you need.
Hunter Pruett
Hunter Pruett 2022 年 7 月 20 日
I am having this same issue. I am trying to open and run a LabView file, which I can do successfully with code from the following website (code follows):
https://www.mathworks.com/matlabcentral/answers/391119-how-can-you-call-a-labview-vi-from-matlab-script
e=actxserver('LabVIEW.Application');
vipath='C:\Users\NI\Desktop\test.vi';
vi=invoke(e,'GetVIReference',vipath);
!start C:\Users\NI\Desktop\test.vi
vi.Run;
The issue I have is that once the 'vi.Run' command has been executed, matlab waits until the LabView script is manually aborted before I can run any other code. I am controlling a servo from matlab and need the two to be running simultaneously. Anyone know if this is possible?

サインインしてコメントする。


Cameron
Cameron 2013 年 6 月 19 日
Can anybody add some go-by code on how I would type commands, send files, etc in the externally opened program? I want to run hyperterminal externally with Matlab and send/receive text automatically on teh opened serial port.

Veronica Escobar Ruiz
Veronica Escobar Ruiz 2015 年 9 月 9 日
Hi Cenk OZAN, did you find a solution for your problem? I have the same issue. I tried, without success, the solutions above and also the solution below.
[status1,cmdout1]=system('explorer /select ,"InputFile.txt"')
[status2,cmdout2]=system('ExeProgram.exe','-echo')
Hope someone can help us.

Javier Valdes
Javier Valdes 2016 年 8 月 9 日
編集済み: Walter Roberson 2016 年 8 月 9 日
I think that the keyinject function https://www.mathworks.com/matlabcentral/fileexchange/40001-keyinject could be useful to control that external application from MATLAB (if the external application has a named window).

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by