can i call app designer CallBack Functions outside the app ?
이전 댓글 표시
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
답변 (1개)
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
Ibrahim Essam
2017년 4월 13일
Adam
2017년 4월 13일
The callback itself has to be private in appdesigner, there's no reason at all to make it public anyway, but what you do in that private function is entirely up to you. You can call a function from anywhere else within that private callback. e.g.
function buttonpushedcallback( app, event )
myFunction( ... )
end
Sarah Bell
2018년 4월 17일
Hi Adam! Just wondering if you could help me? This is pretty unrelated to the original question but I'm trying to use appdesigner to build an RT60 calculator for an assignment for my university. So far, I'm having no issues with the code I have written myself, but the code that matlab has generated has a section that is as follows:
methods (Access = private)
function createComponents(app)
The program is finding issues with the '=', and the ')' on the first line of code, and 'function' in the second line, and I cannot for the life of me figure out how to fix this issue. Any help would be greatly appreciated and you're the only person I've come accross with a working knowledge of appdesigner (even my lecturers have no idea how it works).
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?
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!