Why do SYSTEM commands (like LS) not function as expected when I call them from MATLAB 7.11 (R2010b) ?

3 ビュー (過去 30 日間)
I use the LS command to obtain a list of all the MAT files in a directory and its subdirectories. When I put them in a string, I notice that the first few lines that are displayed are garbage.
A similar unexpected behavior occurs when I execute other linux commands from MATLAB using the SYSTEM command.

採用された回答

MathWorks Support Team
MathWorks Support Team 2013 年 4 月 26 日
編集済み: Edric Ellis 2018 年 12 月 13 日
This behavior is due to interactions between MATLAB system command and underlying Linux shell. In particular, some terminal settings could lead to additional characters being returned by the call to the Unix shell.
To work around this issue try the following within MATLAB:
Before issuing any commands on the MATLAB command prompt:
1) Set MATLAB_SHELL environment variable to /bin/sh:
>> setenv('MATLAB_SHELL','/bin/sh');
2) Test the command that is causing the error.
3) Modify your .bashrc/.cshrc files to set MATLAB_SHELL to /bin/sh
Note: it is possible for step 1 to not fix the issue on its own. If just setting MATLAB_SHELL within MATLAB does not resolve the issue:
1) Shut down MATLAB
2) Modify your .bashrc/.cshrc files to set MATLAB_SHELL to /bin/sh
3) Open a new Linux terminal
4) Start MATLAB
5) verify whether you get correct output
If neither approaches resolve the issue, and you are issuing custom Linux commands via the SYSTEM call or the ! operator try the following:
If your command takes the format:
>> [a, b] = system('foo')
replace it with
>> [a, b] = system('foo < /dev/null')
Using the < /dev/null redirect will disable interactive input from MATLAB and should remove character corruption from the output.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

タグ

製品


リリース

R2010b

Community Treasure Hunt

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

Start Hunting!

Translated by