I am having a lot of trouble in trying to talk to multiple
GUIs. I have created fig1 and fig2 which have seperate fig
and m files. Fig1 has a Text Box and fig2 has a Button. What
I would like to do is control something in fig1 by doing
something in fig2 e.g. change the text in TextBox of fig1 by
pressing the button in fig2. Can someone please tell me how
I should go by it? I start in fig2 and then
h = fig1;
I see fig1 but I cannot control anything beyond that... Any
suggestions?
"Amol " <amol.borkar@gmail.com> wrote in message
<foglbe$o9o$1@fred.mathworks.com>...
> I am having a lot of trouble in trying to talk to multiple
> GUIs. I have created fig1 and fig2 which have seperate fig
> and m files. Fig1 has a Text Box and fig2 has a Button. What
> I would like to do is control something in fig1 by doing
> something in fig2 e.g. change the text in TextBox of fig1 by
> pressing the button in fig2. Can someone please tell me how
> I should go by it? I start in fig2 and then
>
> h = fig1;
>
> I see fig1 but I cannot control anything beyond that... Any
> suggestions?
Hi Amol,
You have to define the uicontrol handle as global so that
you can control it from outside the file.
for example:
Fig1 m-file:
function EditBox_CreateFcn(hObject, eventdata, handles)
global hObject_EditBox
hObject_EditBox = hObject;
function EditBox_Callback(hObject, eventdata, handles)
global EditBox
Fig2 m-file:
function Button_Callback(hObject, eventdata, handles)
global hObject_EditBox
set(hObject_EditBox, 'String', 'SUCCESS');
"Ashwini Deshpande" <vd.ashwini@mathworks.com> wrote in
message <fognl6$nc1$1@fred.mathworks.com>...
> "Amol " <amol.borkar@gmail.com> wrote in message
> <foglbe$o9o$1@fred.mathworks.com>...
> > I am having a lot of trouble in trying to talk to
multiple
> > GUIs. I have created fig1 and fig2 which have seperate
fig
> > and m files. Fig1 has a Text Box and fig2 has a
Button. What
> > I would like to do is control something in fig1 by
doing
> > something in fig2 e.g. change the text in TextBox of
fig1 by
> > pressing the button in fig2. Can someone please tell
me how
> > I should go by it? I start in fig2 and then
> >
> > h = fig1;
> >
> > I see fig1 but I cannot control anything beyond
that... Any
> > suggestions?
> Hi Amol,
>
> You have to define the uicontrol handle as global so that
> you can control it from outside the file.
>
> for example:
> Fig1 m-file:
> function EditBox_CreateFcn(hObject, eventdata, handles)
> global hObject_EditBox
> hObject_EditBox = hObject;
>
> function EditBox_Callback(hObject, eventdata, handles)
> global EditBox
>
> Fig2 m-file:
> function Button_Callback(hObject, eventdata, handles)
> global hObject_EditBox
> set(hObject_EditBox, 'String', 'SUCCESS');
>
> i hope this will work, if not plz let me know.
>
> Ashwini
>
No need for globals here
You can get the other gui windows handles structure (if you
use guide and guidata..):
the_other_window_handles = guidata(otherfigure_handle);
To find the other figures handle assign Tag to your GUI
figures and:
findobj('Tag','Myfirstguifig_orwhatever_the_tag_is')
If you don't use guide and code the whole gui, you can
still manually save a struct of the handles to the userdata
of the figure. Or use guidata here too.
Or you can just add the Tag to your single button or edit
boxand find that with findobj.
It works! Thanks. Althought we don't need the global
variable in EditBox_Callback. It works without it too.
"Ashwini Deshpande" <vd.ashwini@mathworks.com> wrote in
message <fognl6$nc1$1@fred.mathworks.com>...
> "Amol " <amol.borkar@gmail.com> wrote in message
> <foglbe$o9o$1@fred.mathworks.com>...
> > I am having a lot of trouble in trying to talk to multiple
> > GUIs. I have created fig1 and fig2 which have seperate fig
> > and m files. Fig1 has a Text Box and fig2 has a Button. What
> > I would like to do is control something in fig1 by doing
> > something in fig2 e.g. change the text in TextBox of fig1 by
> > pressing the button in fig2. Can someone please tell me how
> > I should go by it? I start in fig2 and then
> >
> > h = fig1;
> >
> > I see fig1 but I cannot control anything beyond that... Any
> > suggestions?
> Hi Amol,
>
> You have to define the uicontrol handle as global so that
> you can control it from outside the file.
>
> for example:
> Fig1 m-file:
> function EditBox_CreateFcn(hObject, eventdata, handles)
> global hObject_EditBox
> hObject_EditBox = hObject;
>
> function EditBox_Callback(hObject, eventdata, handles)
> global EditBox
>
> Fig2 m-file:
> function Button_Callback(hObject, eventdata, handles)
> global hObject_EditBox
> set(hObject_EditBox, 'String', 'SUCCESS');
>
> i hope this will work, if not plz let me know.
>
> Ashwini
>
"Amol " <amol.borkar@gmail.com> wrote in message
<foglbe$o9o$1@fred.mathworks.com>...
> I am having a lot of trouble in trying to talk to multiple
> GUIs. I have created fig1 and fig2 which have seperate fig
> and m files. Fig1 has a Text Box and fig2 has a Button. What
> I would like to do is control something in fig1 by doing
> something in fig2 e.g. change the text in TextBox of fig1 by
> pressing the button in fig2. Can someone please tell me how
> I should go by it? I start in fig2 and then
>
> h = fig1;
>
> I see fig1 but I cannot control anything beyond that... Any
> suggestions?
Another way of doing it.
doc setappdata
doc getappdata
I think there is a small example on the FEX too on this issue.
HTH
Vihang
In article <foglbe$o9o$1@fred.mathworks.com>, amol.borkar@gmail.com
says...
> I am having a lot of trouble in trying to talk to multiple
> GUIs. I have created fig1 and fig2 which have seperate fig
> and m files. Fig1 has a Text Box and fig2 has a Button. What
> I would like to do is control something in fig1 by doing
> something in fig2 e.g. change the text in TextBox of fig1 by
> pressing the button in fig2. Can someone please tell me how
> I should go by it? I start in fig2 and then
>
> h = fig1;
>
> I see fig1 but I cannot control anything beyond that... Any
> suggestions?
>
Nested functions can help you. See examples on matlabcentral or my
blog.
I got most of the multiple gui control working using the
global variables approach. Now I am trying to build a VCR
type application where I have the plot in one figure and the
VCR controls in the other figure. I am able to control
everything except display things on the plot since there
doesnt seem to be a call back where I can set a global
variable. Any suggestions?
"Amol " <amol.borkar@gmail.com> wrote in message
<ftt4mp$3p$1@fred.mathworks.com>...
> I got most of the multiple gui control working using the
> global variables approach. Now I am trying to build a VCR
> type application where I have the plot in one figure and the
> VCR controls in the other figure. I am able to control
> everything except display things on the plot since there
> doesnt seem to be a call back where I can set a global
> variable. Any suggestions?
Hai,
To define axes handles as global variable u need not have
callback function for it. Try out the following:
define the Tag of axes object as 'plot', and make its handle
as global parameter in opening function of the GUI
m_file 1:
function GUI_openingFcn(hObject, eventdata, handles)
global h_plot
h_plot = handles.plot;
m_file 2:
function myfile
global h_plot
axes(h_plot);
t = 0:0.01:1;
x = sin(2*pi*3*t);
plot(t,x) %%% now this signal will be plotted in the axes of
1st GUI.
Works well. Thanks allot Ashwini! For some reason when I had
tried this same approach before, it failed. But it works
now. Thanks again for all the feedback from everyone.
Tags for this Thread
Add a New Tag:
Separated by commas
Ex.: root locus, bode
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.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.