can i call app designer CallBack Functions outside the app ?
7 次查看(过去 30 天)
显示 更早的评论
hello
i want to know if it is possible to call for example
buttonpushedcallback()
from an external .m script
so i want to process some data in my matlab script then i call callbacks functions
i tried this
a=myapp
a.buttonpushedcallback(a)
but it gave me error no class or public property called buttonpushedcallback in myapp
0 个评论
回答(1 个)
Adam
2017-4-12
编辑:Adam
2017-4-12
Yes, it is possible, but you need to understand the basics of function scope.
a=myapp
a.buttonpushedcallback(a)
would be wrong in all contexts. You either put a. at the front or you pass a in as an argument, you don't do both because they amount to the same thing so you would be passing it in twice, as the first two arguments with this syntax.
You use
a.buttonpushedcallback( )
or
buttonpushedcallback( a )
if a is an object of a class and buttonpushedcallback is a method of that class. For a method that is not part of the class you just call
buttonpushedcallback( )
If you really want you can have a method that is external to the class that still takes an object of it as first argument:
buttonpushedcallback( a )
but you cannot use the a.buttonpushedcallback syntax here. Quite why you would want to do this I don't know, since if it takes the class object as argument it should be a method of the class in general, but it is possible.
For a callback though you generally need to pass in two arguments representing the source and event data though also for it to be recognised as a valid callback signature.
5 个评论
Adam
2018-4-20
That sounds like you just ave a syntax error somewhere above that in your code. Check for a missing 'end' from previous functions or method blocks. Selecting everything (e.g. Ctrl + A) and then auto-indenting with Ctr + I can help you to easily spot missing 'end' statements.
Sarah Bell
2018-4-22
Thank you so much! This just fixed my code, and now I can not only submit it 14+ hours early but I'm probably going to get the best mark I've ever had on any coding based coursework, so thank you again!
While I have you here, my boyfriend is also doing coding coursework and was wondering if you happen to know anything about the Kernighan-Lin (or KL) algorithm in Matlab?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!