0

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

ben
  • 473
  • 2
  • 9
  • 21

1 Answers1

0

You can use the nargin matlab command to check for the number of input arguments. For more information check this: http://www.mathworks.com/help/matlab/ref/nargin.html

ThP
  • 2,312
  • 4
  • 19
  • 25