フィルターのクリア

Can I send output from shell commands (with !) to a Matlab variable?

9 ビュー (過去 30 日間)
Alec Nagel
Alec Nagel 2012 年 11 月 25 日
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 件のコメント
Walter Roberson
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
Alec Nagel 2012 年 11 月 26 日
編集済み: Alec Nagel 2012 年 11 月 26 日
Thanks for that info, Walter!
@Matt: The question was partly out of general curiosity, but it was prompted by needing to retrieve the current directory name without the path.
[~,dirName]=system('basename $(pwd)')
works nicely, but I guess I could accomplish the same by
foo = regexp(pwd,'/','split');
dirName = foo{end}
Not quite sure which one I prefer in this case, but I'm sure there are other cases in which system() will prove useful.

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

採用された回答

Jan
Jan 2012 年 11 月 25 日
What about using system() instead?

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by