Skip to main content

13.4) System Commands: Windows Examples


[matlab]
>> [status result]=system('dir')
[/matlab]

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

[matlab]
>> [status result]=system('dir', '-echo')
[/matlab]

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

[matlab]
>> [status result]=system('unknown command')
status=1
result= 'unknown command' is not recognized as an internal or external command, operable program or batch file
>>
[/matlab]

Another useful Windows related Matlab function is winopen, which opens files in the appropriate application.

Syntax: winopen(filename)

For example, if you have a favourite Windows program for viewing NetCDF files, then:

[matlab]
>> filename='data_file.nc'
>> winopen(filename)
[/matlab]