functionmatlabanonymous-function

Is there a way to make an anonymous function without output?


Is there a way to make an anonymous function without output?

I have variable for function_handle whose starting, default value is to do nothing. So I am doing func=@()[];. But I am also curious if there is a way to truly do nothing and output nothing like a .m file for a function that has no return.

Whichever approach, I would still like isa(func,'function_handle') to return true.


Solution

  • To return multiple outputs from an anonymous function you can use deal. This also works to return no output. In addition, (thanks to @Wolfie), varargin can be used to allow a variable number of inputs:

    func = @(varargin) deal();