Sending DOS command to execute Matlab Function and getting the output back to DOS

조회 수: 1 (최근 30일)
Michel
Michel 2014년 9월 30일
댓글: Alberto 2014년 10월 3일
Hello,
I need to have a command be sent via DOS to execute a script/function. I'm already able to do this and it opens Matlab and shows the result of the function through the Matlab Command Window. I was wondering if there was a way to display the output in DOS command prompt?
thank you and I'd greatly appreciate the help.
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2014년 9월 30일
Michel - is it just that you want to view the output (out of curiosity) or do you want to use the output in some way?
The data can be written to a log file and you can periodically view the contents of that file (from another CMD window) using the type command followed by the log file name.
A nicer alternative would be to use a command similar to the UNIX tail -f filename which writes to the window the tail end of the file (and continually does so). There are Windows equivalents to this function...perhaps you can try one of these (unless you already have one).
Michel
Michel 2014년 10월 2일
Hi Geoff and thanks for your comment.
The answer to your first question is actually both. What I am actually doing is sending DOS commands to Matlab via Labview. In a top level I'm controlling instruments via Labview and our Design team uses Matlab scripts for tests, so I wanted to combine both of these worlds. As such, I am sending to execute matlab scipt command via DOS through Labview, but in doing so, I have no feedback, I do get the response, but it is logged in Matlab Command Window.
Thanks! yes, I actually got as far as using -logfile command in DOS to save the result. I was hoping there was something I could use to get the result back to DOS, then the result would therefore be much easily ex tractable and used for other means. I have to think of how to read from file in Labview, I could do this, but that's more code and alterations to our current existing one that I am trying to avoid.
Thanks again for your input! Michel

댓글을 달려면 로그인하십시오.

답변 (1개)

Alberto
Alberto 2014년 10월 1일
You have the command 'dos' so u can interpret some DOS command line, and catch the result of it. I extracted a few lines in the help of Matlab:
dos command
status = dos('command')
[status,result] = dos('command')
[status,result] = dos('command','-echo')
As an example:
[s, w] = dos('dir');
Is is what you needed? Good Luck
  댓글 수: 2
Michel
Michel 2014년 10월 2일
Thanks, I did saw this before while looking through google. I believe I need to add these lines to the pre-existing Matlab code correct? This is something that Matlab talks to DOS in other words. I have literally 100's of Matlab scripts, I do not wish to update them all :(
Alberto
Alberto 2014년 10월 3일
With the instruction dos('dir') you can extract all files you have. Later, you can select which of them to use according to your own criteria. The selection can be done using regular expressions.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by