Note two things:
- You have your function set up to accept a single input argument.
- When you run an application from the Windows command line, arguments are passed in as strings.
So if you type mysum 1
(either in MATLAB on the uncompiled program, and I would guess also if you do this from the Windows command line on the compiled program, although I haven't tested this) it will work, giving the answer 1
, and if you type mysum [1,2]
it will work, giving the answer 3
. Note that mysum [1,2]
is different from mysum([1,2])
, as it is being passed the string '[1,2]'
, not the array of doubles [1,2]
.
But if you type mysum 1 2
it will fail, as you are now passing two string input arguments in, and your function is set up to only accept one.
Rewrite your function so that it accepts a variable number of input arguments (take a look at varargin
to achieve that), applies str2num
in turn to each of the inputs (which will be varargin{1}
to varargin{n}
if you've used varargin
), and then sums them individually.