Using guidata or setappdata seem to call OpeningFcn

1 次查看(过去 30 天)
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

采纳的回答

Geoff Hayes
Geoff Hayes 2022-3-31
@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 个评论
Gorm Dannesboe
Gorm Dannesboe 2022-4-1
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 2022-4-1
@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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

产品


版本

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by