%% Functions with Multiple Inputs or Outputs
% Anonymous functions require that you explicitly specify the input arguments as you would for a standard function, separating multiple inputs with commas. For example, this function accepts two inputs, x and y:

myfunction = @(x,y) (x^2 + y^2 + x*y);

x = 1;
y = 10;
z = myfunction(x,y)

%
% However, an anonymous function returns only one output. If the expression in the function returns multiple outputs, then you can request them when you invoke the function handle.
% For example, the ndgrid function can return as many outputs as the number of input vectors. This anonymous function that calls ndgrid returns only one output (mygrid). Invoke mygrid to access the outputs returned by the ndgrid function.

c = 10;
mygrid = @(x,y) ndgrid((-x:x/c:x),(-y:y/c:y));
[x,y] = mygrid(pi,2*pi);

%
% You can use the output from mygrid to create a mesh or surface plot:

z = sin(x) + cos(y);
mesh(x,y,z)

% Copyright 2015 The MathWorks, Inc.