Set handles of another GUI?

Hi,
Is there a way to set handles of another GUI? I have a main GUI which prompt a sub GUI. In the sub GUI,when a button is pressed and it will set the main GUI visible off.
set(handles.fig1,'Visible','off');
I place this code on the the button of my sub GUI. fig1 is the handles of my main GUI. However to code has error because the sub GUI doesnt know the handles fig1.

 Accepted Answer

Set the Tag parameter for the main GUI's figure, and then in the sub-GUI
handles.fig1 = findobj(0,'Type','figure','Tag','TheTagYouSet');

7 Comments

i use this command, matlab returns an array of figure not handle
use a unique Tag for every figure that you need to be able to refer to .
I have twos GUIs, GUI1 and GUI2.
GUI2 is sub - GUI of GUI1 that mean when i click on any component in GUI1, GUI2 will be opened
And, i want to use data in GUI1 for GUI2. i use code below in function
GUI2_OpeningFcn(hObject, eventdata, handles, varargin) of GUI2
function GUI2_OpeningFcn(hObject, eventdata, handles, varargin):
hgui1 = findobj('Tag','gui1') % i set 'Tag' for GUI1 is "gui1'
if ~isempty(hgui1)
% get handles and other user-defined data associated to Gui1
gui1data = guidata(hgui1); % Store data from hgui1 to gui1data handle
end
guidata(hObject, handles);
when GUI2 runs, matla returns:
Error using guidata (line 87)
H must be the handle to a figure or figure descendent.
I don't know why?
Could you help me?
Please!
Is line 87 the line
gui1data = guidata(hgui1)
?
At the command line command
dbstop if error
and then run your code. When it stops, use the command dbup until it shows you as being in GUI2_OpeningFcn . At that point, examine class(hgui1)
Le Dung
Le Dung on 27 Dec 2018
Edited: Le Dung on 27 Dec 2018
Yes. line 87 in Guidata.m
error(message('MATLAB:guidata:InvalidInput'));
And, i think my problem is at line command:
hgui1 = findobj('Tag','gui1')
matlab return :
hgui1 =
5x1 Figure array:
Figure (vefrf)
Figure (vefrf)
Figure (vefrf)
Figure (vefrf)
Figure (vefrf)
and
gui1data = guidata(hgui1)
this is all warning:
Error using guidata (line 87)
H must be the handle to a figure or figure descendent.
Error in Printedit>Printedit_OpeningFcn (line 65)
gui1data = guidata(hgui1); % Store data from hgui1 to gui1data handle
Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in Printedit (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in vefrf>print_Callback (line 152)
Printedit
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in vefrf (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)vefrf('print_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating Menu Callback
Try
close('all')
now run your program again and see what comes up.
If it still shows multiple items in hgui1 then try
hgui1 = unique(findobj('Tag','gui1'))
If that still returns multiple entries, please show the output of
struct2cell(get(hgui1))
Le Dung
Le Dung on 28 Dec 2018
Edited: Le Dung on 28 Dec 2018
dear walter.
thank you again for your reply.
its very kind of you.
i don’t know why matlab return a array that has many figures.
but, i solved my problem when i use:
gui1data = guidata(hgui1(1)).
my code worked ok

Sign in to comment.

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Asked:

on 16 Jul 2011

Edited:

on 28 Dec 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!