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

 채택된 답변

Rik
Rik 2019년 7월 2일
편집: Rik 2019년 7월 2일

0 개 추천

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

Kristoffer Walker
Kristoffer Walker 2019년 7월 2일
Outstanding; thanks Rik!
Hershin Zarani
Hershin Zarani 2020년 6월 5일
then why is there (x,y) before @(x,y)disp()?
Steven Lord
Steven Lord 2020년 6월 5일
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.
madhan ravi
madhan ravi 2020년 6월 5일
Steven I think his question is why was it used for disp(...) when it doesn’t accept arguments x and y.
Omar Alamoudi
Omar Alamoudi 2021년 12월 20일
I would like to know the name to the question stated by @madhan ravi
Stephen23
Stephen23 2021년 12월 20일
편집: Stephen23 2021년 12월 20일
@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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

릴리스

R2017b

질문:

2019년 7월 2일

편집:

2021년 12월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by