필터 지우기
필터 지우기

applying unix commands in matlab

조회 수: 3 (최근 30일)
artsci4
artsci4 2013년 8월 14일
I have been trying to apply unix commands in the MATLAB environment but it is not working. For example, if I enter this simple command to display the environment variable PATH, the following is the output:
[status, cmdout]=unix('echo $PATH')
status =
0
cmdout =
$PATH
When I apply this same command in cygwin, it gives me a long output pointing to the correct directory. What do I need to do to fix this?
  댓글 수: 3
artsci4
artsci4 2013년 8월 14일
When I apply
[status, cmdout] = unix('printenv SHELL')
cmdout stores 'printenv' is not recognized as an internal or external command, operable program or batch file.
Same with applying: [status, cmdout]=unix('env | grep SHELL')
then it says 'env' is not recognized...
I am using Windows 7. And the MATLAB version is R2012b.
Daniel Shub
Daniel Shub 2013년 8월 14일
I don't have the documentation in front of me, but I am pretty sure the MATLAB UNIX command is not magically and does not give you access to UNIX from a Windows machine.

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

채택된 답변

Walter Roberson
Walter Roberson 2013년 8월 14일
The unix() command does not deliberately pass the command to a Unix command shell. The unix() command and system() command and dos() command are identical (or very nearly so), and all three of them pass the command to the "system shell". Which, on MS Windows, is "cmd.com" or "cmd.exe" or whatever the 64 bit equivalent name is.
If I recall old MS Windows information properly,
system('print PATH')
Note: if you are calling to the system just to look at environment variables, then instead use MATLAB's getenv()
getenv('PATH')
  댓글 수: 7
artsci4
artsci4 2013년 8월 15일
I have tried this same command in cygwin terminal and the output would be successfully stored to the output file.
Walter Roberson
Walter Roberson 2013년 8월 15일
편집: Walter Roberson 2013년 8월 15일
system(sprintf('a.exe ''%s'' > ''%s''', FileIn{i}, FileOut{i})

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

추가 답변 (1개)

artsci4
artsci4 2013년 8월 16일
I fixed the problem. I fixed it apparently by adding the path to my current directory to the Windows Environment Variable PATH. Then the system recognizes the executable file.

카테고리

Help CenterFile Exchange에서 Source Control Integration에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by