Using guidata or setappdata seem to call OpeningFcn

1 回表示 (過去 30 日間)
Gorm Dannesboe
Gorm Dannesboe 2022 年 3 月 31 日
コメント済み: Geoff Hayes 2022 年 4 月 1 日
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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by