How to use the same callback function for 2 different codes

6 views (last 30 days)
Im using GUIDE and I have 2 panels , In one panel when I press a pushbutton the key value is displayed in the static text box , if I want the same key to be displayed in 2nd panel when I click the pushbutton in the first place what must be done. How to use the same callback function used in panel 1 for panel2. I hope this question makes sense

Answers (1)

Walter Roberson
Walter Roberson on 22 Jun 2021
In GUIDE, the easiest approach is to code the shared portion into a function, and call the function from both callbacks .
However... if you want to display the same key to the second panel, then that does not sound to me like using the same callback for two panels: that sounds to me as if you want a single callback to display into two different panels.
In GUIDE, you cannot (at least without difficulty) register the same push-button event to invoke two separate callbacks.
In GUIDE, when you talk about the "same callback function" that would mean shared code that is to apply in multiple circumstances. For example if you had a Radio Button Group then instead of coding a separate callback function for each different radio button, you might want to have the same function invoked no matter which of the radio buttons was pushed, with the code identifying which button it was called from and acting appropriately.

Community Treasure Hunt

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

Start Hunting!

Translated by