title: How to write a function that does not throw a "wrong number of arguments" error
body: <p>I am trying to write a minimal function that can be called with a variable number of arguments but that will not throw a wrong number of arguments error if miscalled.</p>
  
  <p>Here is where I start from :</p>
  
  <pre><code>function varargout=fname(varargin)
  % FNAME
  % Usage: output=fname(input)
  
  % Arguments check
  if(nargin~=1 || nargout~=1)
      disp('Function fname requires one input argument');
      disp('and one output argument');
      disp('Try `help fname`');
      varargout(1:nargout)={0};
      return;
  end
  
  input=varargin{1};
  
  output=input;
  
  varargout(1)={output};
  end
  </code></pre>
  
  <p>However this does not work as I would like it to. Is there a way to write a function that :</p>
  
  <ul>
  <li>never throw a "wrong number of arguments" error (so that the rest of the execution can continue)</li>
  <li>accepts variable number of input and output arguments and checks them inside the function</li>
  <li>(maybe more tricky) if the number of input / output arguments is not correct, does not replace the value of the provided output arguments (so that any misplaced call does not erase the previous value of the output argument)</li>
  </ul>
  
  <p>I am open to any suggestions / other methods.</p>
  
  <p>Thank you for your help.</p>
  
  <p><strong>UPDATE:</strong> thanks to @Amro for his answer, I guess what I miss here is either a call by address of reference for Matlab functions or a way to interrupt a function without returning anything and without stopping the rest of the execution.</p>