For Programmers: Free Programming Magazines  


Home > Archive > Matlab > April 2005 > Re: How can i obtain data from an edit box in a different figure









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: How can i obtain data from an edit box in a different figure
Steve Simon

2005-04-06, 12:54 pm

If the figures were created in GUIDE as separate GUIs, then they will
each have their own 'handles' structure. The 'handles' structure is
stored with each figure (look at the code in GUIDATA, to see how this
works).

If you have the handle for the figure (or even any object in the figure)
in a GUIDE-created GUI, then you can get its particular 'handles'
structure with the code:

% h is the handle for the figure or something in a figure
fig1Handles = guidata(h);

If you are launching one GUI from the other, then one way to handle this
would be to modify their respective M-files, so that they have access to
each other's figure handles. For example, if you launch GUI2 from code
in GUI1, then you would make modifications that look something like this:
------------------------------------------------------------
% in GUI1's code

% call GUI2, passing handle for GUI1 as an input, and returning the
% handle for GUI2's figure
handles.gui2Handle = GUI2(handles.gui1);
% store the modified 'handles' structure
guidata(handles.gui1,handles);

% anywhere that you need access to an object in GUI2, use GUIDATA to
% get GUI2's 'handles' structure
gui2Handles = guidata(handles.gui2Handle);
set(gui2Handles.edit1,'String','example string');
------------------------------------------------------------
% in GUI2's code

% since GUI1's handle was passed as an input, it should be
% available in the OpeningFcn (if you are using MATLAB 6.5 or later)
handles.gui1Handle = varargin{1};
% store the modified 'handles' structure
guidata(handles.gui2,handles);

% the OutputFcn (6.5 or later) already passes the figure handle as an
% output by default, so you shouldn't need to change anything)

% anywhere that you need access to an object in GUI1, use GUIDATA to
% get GUI1's 'handles' structure
gui1Handles = guidata(handles.gui1Handle);
str = get(gui1Handles.edit1,'String');
------------------------------------------------------------


For a more complete example, see:

http://www.mathworks.com/support/so...olution=1-1BAR8

-SteveSimon-



Cooke wrote:
> Hi chaps,
>
> When i click a button in one figure, I need it to obtain the string
> from an edit box in another figure that is also open. I know i need
> to use handles to do this but I cant quite figure out how.
>
> My attempt at using the standard:
>
> get(handles.imageFileName,'String');
>
> does not work as it cannot recognise the object (due to it being in
> the different figure i assume)
>
> any help very appreciated,
>
> G Cooke

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com