When I execute the following:
function [ x ] = addya( varargin )
x=varargin{1};
t=varargin{1};
if(nargin>1)
for i=2:nargin
t=t+varargin(i);
end;
end
x=t;
The error i am getting is:
addya(1,1) ??? Undefined function or method 'addya' for input arguments of type 'double'.
please suggest changes and errors.
Make sure this function is saved in a file called
addya.m
.Moreover, as mentioned by il_raffa there's a typo - inside the loop: you should access
varargin
using{}
.The following code works for me when saved as
addya.m
:Also, I would suggest to refrain from using
i
as a loop index due to possible complication with complex numbers.