Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Big problem sharing data between functions of a GUI

Subject: Big problem sharing data between functions of a GUI

From: Camille Couzi

Date: 28 Oct, 2010 19:34:04

Message: 1 of 3

Hi,
I am having some problem with my shared data between functions in my GUI. Until now I was making it a little bit "not very beatiful", storing some data in text boxes, which I was setting "visible','off', and then putting it in my guidata, but now, I am working with many windows with many functions, and that don't work anymore.
So after reading a lot of documentation, I have 2existential questions:
- what is the difference between guidata and application data (setappdata...)?????
-and what is the difference between making h = guidata(hObject); , and
h = guidata(gcf); this last one stores the guidata information in the current figure, whereas h = guidata(hObject); store it in the current object...??

I am a little bit lost, please, help me,
thanks in advance!
Camille.

Subject: Big problem sharing data between functions of a GUI

From: Sean

Date: 28 Oct, 2010 19:48:04

Message: 2 of 3

.
> So after reading a lot of documentation, I have 2existential questions:
> - what is the difference between guidata and application data (setappdata...)?????
> -and what is the difference between making h = guidata(hObject); , and
> h = guidata(gcf); this last one stores the guidata information in the current figure, whereas h = guidata(hObject); store it in the current object...??

I'll answer the first question and you can derive the second from that. SETAPPDATA/GETAPPDATA are good. GUIDATA is bad. The light and dark side of the force really. At least that's my opinion. I would avoid using GUIDATA whenever possible. Store your stuff in the root directory:

setappdata(0,'FirstString','setappdata is cool');

and retrieve it as necessary

Subject: Big problem sharing data between functions of a GUI

From: Camille Couzi

Date: 29 Oct, 2010 13:29:05

Message: 3 of 3

Hi, thanks for your reply,
but you dudn't really reply to my question, what is the main difference between guidata and getappdata?
Since I have made my entire gui (with plenty of subprograms) using guidata, I think for the moment I am trying to make it run with that.
You tell me :
"Store your stuff in the root directory: setappdata(0,'FirstString','setappdata is cool'); ",
I think that would solve the problem I have in that litte moment: I have two figures, figur2, created from the figure1 which is the main page of my GUI. I create a variable in the figure1, for example:
h.test=[1 2 3];

In the subfigure (figure2) I make a modification to that variable:
h.test(1,3)=5;
guidata(hObject, h);

and then when I ask at the end of figure1 what is the value of h.test, he tells me
h.test=1 2 3
instead of h.test=1 2 5

So basically my GUI is no taking in account the change made in my subfigure 2. How can I solve that? writing
guidata(0, h); instead of guidata(hObject, h); after make the modification in figure2?

Thanks in advance for your help

Camille.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us