MATLAB Answers

0

Several Guis Sharing information

I am making a program with several GUIS. Basically it´s a first GUI for input data, and them few Guis that are open depending of the input option. I am trying with a first simple sample of 2 Guis, and I am using... b=str2double(get(handles.edit1,'String')); setappdata(0,'R',b); secondgui; ... in the first gui, and... a=getappdata(0,'R') set(handles.text2,'String',a) ... in the second gui
This way it works, but I don´t understand why this "0" and don´t know what other labels can I use apart from 0.
I am interested in all possible suggestions Thank you very much.

  댓글 수: 0

로그인 to comment.

답변 수: 2

Sean de Wolski 님의 답변 13 Mar 2012
 채택된 답변

0 is the root matlab handle. Thus you are setting a field 'R' to this MATLAB's instance that can be retrieved from anything in this instance. You could also set it to the handle of a figure so that the figure has a new field (or property), 'R', that can be accessed by anything that has access to that handle. This does mean that if the figure is closed, the info is gone.
Hope this helps.

  댓글 수: 3

That just helps me quite a lot. Thank you very much Sean de Wolski.
I have been trying to use instead of 0, just other handle like "handles.pushbutton1". I thought that it would work but it doesn´t.
Anyway maybe it is even better use the root handles 0, of course if there is no max limits for the number of variables to save, becouse I will have to use about 20 variables.
I am still new in programming and maybe don´t understand still very well this matlab structure with the Guis, handles, etc... If somebody knows a link with clear information about that I would be very pleased.
You can do that (and I did for my first GUI :) but it can be dangerous. I would recommend storing it in the handles.figure1 field since the figure will always be present when the GUI is open. This will then clear all of the info when you close the GUI - added bonus.
I understand that it´s dangerous becouse when you will open another different GUI could get confuse with the variables that still are active... Am I all rigth?
I´m now having problems to use the handles.figure1 instead of 0. I´ll try now to solve it and will coment later my solution
Thanks a lot!

로그인 to comment.


David Dapuero 님의 답변 14 Mar 2012

First Gui
function inputdata_OpeningFcn
setappdata(0,'hMainGui',gcf)
function pushbutton1_Callback
hMainGui = getappdata(0,'hMainGui');
b=str2double(get(handles.edit1,'String'));
setappdata(hMainGui,'Rosa',b);
resultado
**********************************************
Second Gui
function resultado_OpeningFcn
hMainGui=getappdata(0,'hMainGui');
a=getappdata(hMainGui,'Rosa')
That is my solution: Saving into "0" de handles of the MainGui. And acces to this MainGui handles also throw "0" in the second Gui.
Thanks a lot for the help... I am open to any recomendation or reference. David Dapuero

  댓글 수: 0

로그인 to comment.



Translated by