What does @(x,y)myFunction mean?

Folks,
Could someone please point me to documentation that explains what the "@(x,y)" means in the below code?
@(x,y)disp('Hello World!')
Similarly, what do the following mean?
StartFcn = @(~,~)myfile
StartFcn = @myfile
StartFcn = {@myfile, 5, 6}
I am trying to get a timer to execute a specific callback in a GUIDE GUI. In order to get this to work, it seems I really need to understand that syntax.
Thank you,
Kris

 Accepted Answer

Rik
Rik on 2 Jul 2019
Edited: Rik on 2 Jul 2019
The @ symbol generates either a function handle or creates an anonymous function.
You can read more on this doc page.
You third syntax is slightly less obvious. For that one you can find more information here.

6 Comments

Outstanding; thanks Rik!
then why is there (x,y) before @(x,y)disp()?
That indicates the anonymous function accepts two inputs and that inside the anonymous function the first is known as x and the second as y. See the anonymous function documentation page for more information.
Steven I think his question is why was it used for disp(...) when it doesn’t accept arguments x and y.
I would like to know the name to the question stated by @madhan ravi
Stephen23
Stephen23 on 20 Dec 2021
Edited: Stephen23 on 20 Dec 2021
@Omar Alamoudi: because that anonymous function (and indeed all of the other examples shown in the original question) was written as a callback function for a GUI:
If those two input arguments (object and event) are not used, then they can be ignored, as in that example, but they still need to be defined. It would be better to use tildas for this, which makes the intent clearer.
The code is basically a hello-world callback function.

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products

Release

R2017b

Asked:

on 2 Jul 2019

Edited:

on 20 Dec 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!