MATLAB GUI Pushbutton Click Runs Callback Twice

I'm working on improving an inherited GUI to run some calculations, and it requires the user to click a pushbutton to open a browse for an input file (uigetfile()), select/import into MATLAB, and use the data within to do some number-crunching. I've made some modifications to it in GUIDE, and somehow something changed such that every pushbutton click results in its respective callback function being run twice. For example, now the user is prompted to select the input file twice; after it's successfully selected and imported, the command is run again starting with uigetfile(). The calculation is run twice, it saves the results to an external .csv file twice, etc., etc. Everything still runs fine, but every action is repeated.
I haven't made any changes to the callback functions, just the GUI/buttons. I'm not sure what's causing each function to be run twice. There do not appear to be any duplicate buttons on top of one another somehow each being clicked once to run the function twice.
I'm new to GUIDE and so I'm not sure how to effectively debug the tool. Any help is appreciated.
Thanks!

5 commentaires

Rik
Rik le 4 Mai 2020
And is why I discourage everyone to use GUIDE for anything that takes longer than 5 minutes to create.
Can you attach the m file and fig to your question so we can have a look?
Unfortunately I cannot as it's work-related. The only thing in the .m file I can see potentially causing this ties into the guidata(hObject,handles) call at the end of each pushbutton callback function. Is there something like a "run while" or "run until" value/field in a GUI-related struct that gets set/toggled after a callback function is run, telling guidata/gui_mainfcn to not run again?
Rik
Rik le 4 Mai 2020
That is unfortunate.
The call to guidata stores (or retrieves) a struct that is saved with the GUI figure. As the callback you will notice there is something like @(h,e) Button1Callback(h,e,guidata(h)).
I think the only viable strategy would be to put a breakpoint at the start of a callback function and then execute it line by line until you find where it starts repeating.
I've done that already, it's something within guidata/gui_mainfcn I believe.
Would you recommend switching to App Designer instead?
Rik
Rik le 4 Mai 2020
If you're going to re-write your GUI, I would highly encourage looking into this thread.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange

Modifié(e) :

G A
le 14 Juin 2023

Community Treasure Hunt

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

Start Hunting!

Translated by