4

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.

0

1 Answer 1

5

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();
Sign up to request clarification or add additional context in comments.

1 Comment

could make this even more generic by doing @(varargin) deal() then it takes any number of inputs too

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.