Got Questions? Get Answers.
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:
guidata not updating among figures !!!!

Subject: guidata not updating among figures !!!!

From: Camille Couzi

Date: 29 Oct, 2010 13:40:05

Message: 1 of 6

Hi matlabers! I need your help to solve a little problem I am having with my GUI!

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.

Subject: guidata not updating among figures !!!!

From: someone

Date: 29 Oct, 2010 14:36:03

Message: 2 of 6

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <iaeirl$m1u$1@fred.mathworks.com>...
> Hi matlabers! I need your help to solve a little problem I am having with my GUI!
>
> 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.

In the above, what does h refer to?

If h is the handle to figure1 when you set it, then
you need to refer to that specific handle in figure2
when you want to retrieve it. (Not the figure2 handle.)

You could also use setappdata & getappdata instead.

Subject: guidata not updating among figures !!!!

From: Camille Couzi

Date: 29 Oct, 2010 15:48:04

Message: 3 of 6

"someone" <someone@somewhere.net> wrote in message <iaem4j$1ut$1@fred.mathworks.com>...
> "Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <iaeirl$m1u$1@fred.mathworks.com>...
> > Hi matlabers! I need your help to solve a little problem I am having with my GUI!
> >
> > 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.
>
> In the above, what does h refer to?
>
> If h is the handle to figure1 when you set it, then
> you need to refer to that specific handle in figure2
> when you want to retrieve it. (Not the figure2 handle.)
>
> You could also use setappdata & getappdata instead.

thanks!!!!!! h is the handle where I store all my data, h.fig1 is the handle of my figure one. so I put guidata(h.fig1,h), and that worked!
One question: what is the difference between guidata and getappdata?
Thank you very much!!!

Subject: guidata not updating among figures !!!!

From: Steven_Lord

Date: 29 Oct, 2010 15:55:12

Message: 4 of 6



"someone" <someone@somewhere.net> wrote in message
news:iaem4j$1ut$1@fred.mathworks.com...
> "Camille Couzi" <camillecouzi@yahoo.fr> wrote in message
> <iaeirl$m1u$1@fred.mathworks.com>...
>> Hi matlabers! I need your help to solve a little problem I am having with
>> my GUI! 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.
>
> In the above, what does h refer to?
>
> If h is the handle to figure1 when you set it, then you need to refer to
> that specific handle in figure2 when you want to retrieve it. (Not the
> figure2 handle.)
>
> You could also use setappdata & getappdata instead.

And if your second callback is updating the variable but the first callback
already has that variable in its workspace, you will need to have the first
callback check for an update to that variable using GUIDATA in order for its
copy to reflect those changes. Making a change to one instance of a
variable in one workspace does NOT necessarily mean another instance in
another workspace will also be changed.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: guidata not updating among figures !!!!

From: someone

Date: 29 Oct, 2010 16:14:04

Message: 5 of 6

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <iaeqbk$bqp$1@fred.mathworks.com>...
> "someone" <someone@somewhere.net> wrote in message <iaem4j$1ut$1@fred.mathworks.com>...
> > "Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <iaeirl$m1u$1@fred.mathworks.com>...
> > > Hi matlabers! I need your help to solve a little problem I am having with my GUI!
> > >
> > > 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.
> >
> > In the above, what does h refer to?
> >
> > If h is the handle to figure1 when you set it, then
> > you need to refer to that specific handle in figure2
> > when you want to retrieve it. (Not the figure2 handle.)
> >
> > You could also use setappdata & getappdata instead.
>
> thanks!!!!!! h is the handle where I store all my data, h.fig1 is the handle of my figure one. so I put guidata(h.fig1,h), and that worked!
> One question: what is the difference between guidata and getappdata?
> Thank you very much!!!

% Aside from

doc setappdata
doc getappdata
doc guidata
doc userdata

% you might also look at this thread:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/293275#785758

% To Steven Lord
% This topic might be a good submission for the MATLAB FEX.

Subject: guidata not updating among figures !!!!

From: someone

Date: 29 Oct, 2010 16:21:04

Message: 6 of 6

"someone" <someone@somewhere.net> wrote in message <iaersc$lvj$1@fred.mathworks.com>...
> "Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <iaeqbk$bqp$1@fred.mathworks.com>...
> > "someone" <someone@somewhere.net> wrote in message <iaem4j$1ut$1@fred.mathworks.com>...
> > > "Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <iaeirl$m1u$1@fred.mathworks.com>...
> > > > Hi matlabers! I need your help to solve a little problem I am having with my GUI!
> > > >
> > > > 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.
> > >
> > > In the above, what does h refer to?
> > >
> > > If h is the handle to figure1 when you set it, then
> > > you need to refer to that specific handle in figure2
> > > when you want to retrieve it. (Not the figure2 handle.)
> > >
> > > You could also use setappdata & getappdata instead.
> >
> > thanks!!!!!! h is the handle where I store all my data, h.fig1 is the handle of my figure one. so I put guidata(h.fig1,h), and that worked!
> > One question: what is the difference between guidata and getappdata?
> > Thank you very much!!!
>
> % Aside from
>
> doc setappdata
> doc getappdata
> doc guidata
> doc userdata
>
> % you might also look at this thread:
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/293275#785758
>
> % To Steven Lord
> % This topic might be a good submission for the MATLAB FEX.
OOPS, I meant the MATLAB FAQ.

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