Can I send output from shell commands (with !) to a Matlab variable?
이전 댓글 표시
I sometimes use shell commands from within Matlab scripts by using ! myCommand. I was recently in a situation where I needed to manipulate the output of this command in my Matlab script. Thus my question: Is there any way to send the output from a shell command to a Matlab variable?
(I realize there's a workaround in writing to a file and reading that in to Matlab, something along the lines of
! myCommand > myFile.txt
myOutput = importdata('myFile.txt')
! rm myFile.txt
but I was wondering if there was a more elegant way.)
댓글 수: 3
I guess Jan answered your question, but it might be worthwhile if you elaborated on why this is necessary in your particular case. In many cases, MATLAB has its own commands that substitute for shell commands, so maybe what you're trying to do through the shell is unnecessary. For example, you shouldn't really have to do things like
! rm myFile.txt
when MATLAB already has its own command for file deletion
delete myFile.txt
Same goes for file/directory copying, moving, listing, etc...
Walter Roberson
2012년 11월 25일
편집: Walter Roberson
2012년 11월 25일
movefile() on Linux systems uses "mv" flag ('-p') that is not valid for NFS filesystems.
Someone (Jan?) demonstrated that some of the file-oriented commands are much slower than using the OS commands.
Alec Nagel
2012년 11월 26일
편집: Alec Nagel
2012년 11월 26일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!