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 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