How to access app designer GUI pushbutton callback inside my function?

12 views (last 30 days)
I'm building a GUI via AppDesigner.
I have 2 push buttons: pushBtn_A & pushBtn_B.
pushBtn_A has its own "button pushed" callback.
pushBtn_B has its own "button pushed" callback.
I also have my own created function: my_func.
I'm trying to do the following:
inside pushBtn_B callback, I call for my function (my_func). And inside my_func, I'd like to call the pushBtn_A callback.
But once I'm inside my_func, it doesn't recognize pushBtn_A callback.
Error using mainRunner_GUI/pushBtnA_pushBtnButtonPushed
Cannot access method 'pushBtnA_pushBtnButtonPushed' in class 'mainRunner_GUI'.
How this can be solved?
Geoff Hayes
Geoff Hayes on 8 Mar 2022
@Mark Golberg - is your function defined within the GUI or is it a separate file? Can you show the code for this function and how it expects to use the push button A callback function?
Mark Golberg
Mark Golberg on 9 Mar 2022
@Geoff Hayes Thank you.
Please see snapshot below.
My custom function defined within a seperate *.m file.
Is it clearer now?

Sign in to comment.

Answers (1)

Rik on 8 Mar 2022
My suggestion would be to move the code you want to call to a separate function. In my view, the callback of an object should only gather data from the user and pass those off to functions that do the actual work. If you want to call the same code from A as from B that is a clear sign that it is more general than a simple callback.
Mark Golberg
Mark Golberg on 10 Mar 2022
according to snapshot below --> takeLeft_pushBtn is already "public", isn't it?
Can you advice please how can I make the method public?
I like using App Designer (and previosuly GUIDE) because of the ease of "drag & drop" for components creation. Don't like to define all the positions, by myself. Always a headache with setting it right... and then if you want to re-arrange your objects, it's a nightmare...
Rik on 10 Mar 2022
Your screenshot suggests the handle to the object itself is stored in a public property. The callback takeLeft_pushBtnButtonPushed is a method, not a property. I don't know if it is possible in AppDesigner to set a method to public. As I said, I don't work with AppDesigner myself, so I would have to do the same as you: look in the menus and google if I don't see anything
I understand the appeal of GUIDE/AppDesigner. I like them for rapid prototyping. Once you have determined the layout you can put those positions in code. For some situations I use code to determine the position based on the number of buttons I need to create. Once you are no longer prototyping, layout changes should be very rare, so the additional effort is not really relevant. Compare the time you've been struggling with this problem to the half hour it takes to change all the position arguments of your components.

Sign in to comment.


Find more on Interactive Control and Callbacks 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!