can i call app designer CallBack Functions outside the app ?

12 views (last 30 days)
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

Answers (1)

Adam
Adam on 12 Apr 2017
Edited: Adam on 12 Apr 2017
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 Comments
Adam
Adam on 20 Apr 2018
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
Sarah Bell on 22 Apr 2018
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?

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!