Skip to main content

13.3) System Commands: Unix Examples


[matlab]
>> [status result]=unix('ls -ltr')
[/matlab]

result will contain a string (including the carriage return) of the contents of the current directory. Using the "-echo" command will display the Unix command output, which is equivalent to missing the trailing semi-colon (;) from the Matlab command.

[matlab]
>> [status result]=unix('ls -ltr', '-echo')
[/matlab]

What happens if we attempt to use a string which is not a recognized Unix command?

[matlab]
>> [status result]=unix('unknown command')
status=1
result= unknown command: Command not found
[/matlab]