Using guidata or setappdata seem to call OpeningFcn

1 visualizzazione (ultimi 30 giorni)
Hi Community,
I have made a GUI using GUIDE in Matlab R2016a that plots simulation data. It is mostly working fine, but recently I have added a second GUI for importing measurement data.
In the second GUI I browse to the data, select the data I want to plot, and send to the main GUI using setappdata.
setappdata(LoopGainPlotterGUIv1_5,'NonInvasiveData',NonInvasiveData);
In the main GUI I call the data using getappdata:
NonInvasive.Data = getappdata(LoopGainPlotterGUIv1_5,'NonInvasiveData');
The data is transfered just fine, and I can plot it, but it seems like all my handle variables in the main GUI (LoopGainPlotterGUIv1_5) are being reset as in the opening function of the main GUI. This is a big problem for me since it is then no longer possible for the GUI to know what has been plotted etc.
I have also noticed that if I write the following in the command window, then it also resets my handles in the main GUI. At least that is what it looks like since the written out variables are all wrong and the GUI no longer works as intended.
B = guidata(LoopGainPlotterGUIv1_5)
If I just read out handles by adding
handles
to a button callback then all is good, as long as I haven't passed data from the second GUI.
I have looked far and wide for an explanation, but cannot find anywhere mentioning such behaviour. Is it really so, that the opening function is being called using setappdata or guidata outside the GUI figure?
Best Regards,
Gorm Dannesboe

Risposta accettata

Geoff Hayes
Geoff Hayes il 31 Mar 2022
@Gorm Dannesboe - I suspect that everytime you call the GUI by name, LoopGainPlotterGUIv1_5, you are creating a new instance of the GUI. If you want to communicate between two open GUIs (GUIs created in GUIDE) then you can do something similar to what is discussed at Pass Data between GUIs.
  2 Commenti
Gorm Dannesboe
Gorm Dannesboe il 1 Apr 2022
Thank you. I hadn't stumpled upon that post. Doing it like that solved my problem.
Though I still find it odd the opening function is called all these times.
Geoff Hayes
Geoff Hayes il 1 Apr 2022
@Gorm Dannesboe - if LoopGainPlotterGUIv1_5 is the name of the GUI, then calling this will instantiate a new instance of the GUI and so call the OpeningFunc every time.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su App Building in Help Center e File Exchange

Prodotti


Release

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by