I'm trying to understand how to write a script such that when compiled into a standalone windows executable, the user can optionally pass a command-line-argument, for usage in the script.
For example, the 'exist' line below generates a matlab error: 'Not enough input arguments' when no parameter is passed.
function test ( optionalUserEnteredFilename )
if exist(optionalUserEnteredFilename , 'file') == 2
fid = fopen ( optionalUserEnteredFilename , 'r');
else
fid = fopen ('DefaultFile.txt', 'r');
end
end
How can the script check (and use) an argument if it was entered in the command line, but not generate an eror when omitted?
i.e. c:>test.exe myfile.dat and c:>test.exe