passing data & connecting gui(s)

1 view (last 30 days)
Hossein Saberi
Hossein Saberi on 23 Nov 2018
Edited: Hossein Saberi on 23 Nov 2018
Hi, i have 3 gui and i have 3 tab like this file that i upload how can i connect them together
every 3 gui icludes axes, pushbuttom,...
  2 Comments
Preethi
Preethi on 23 Nov 2018
you want to pass data between the gui??
Hossein Saberi
Hossein Saberi on 23 Nov 2018
yes i can find this
function pushbutton1_Callback(hObject, eventdata, handles)
% get the handle of Gui1
h = findobj('Tag','Gui1');
% if exists (not empty)
if ~isempty(h)
% get handles and other user-defined data associated to Gui1
g1data = guidata(h);
% maybe you want to set the text in Gui2 with that from Gui1
set(handles.text1,'String',get(g1data.edit1,'String'));
% maybe you want to get some data that was saved to the Gui1 app
x = getappdata(h,'x');
end
but i dont understand how it work

Sign in to comment.

Accepted Answer

Jan
Jan on 23 Nov 2018
A specific question is more efficient than "I don't understand how it works". The code example contains useful comments already.
% get the handle of Gui1
h = findobj('Tag','Gui1');
Is this clear so far? Each GUI element, e.g. a figure, has a unique "handle", which can be used to access the object. Instead of seaching all GUI elements, e.g. all buttons, lines and menu entries, it is faster to restrict the search to the wanted object:
h = findob(allchild(0), 'flat', 'Tag', 'Gui1');
Now only figures are searched.
% if exists (not empty)
if ~isempty(h)
A matching figure was found.
% get handles and other user-defined data associated to Gui1
g1data = guidata(h);
Now you can access the handles struct of the found figure. Do not get confused by the name "handles". It does contain handles of the GUI elements created by GUIDE, but you can store anything in this struct also.
Now the callback can access all elements of the figure with the tag 'Gui1', e.g. getting the values of toggle-buttons or draw in existing axes.
Search in this forum for "share data between callbacks". This works for callbacks of different figures also.
  1 Comment
Hossein Saberi
Hossein Saberi on 23 Nov 2018
Edited: Hossein Saberi on 23 Nov 2018
Thank you for your help jan
I used 8 guide because of the lack of space in guide, and now I want to put all the information (e.g. position , ...) in one m-file
do u think can i call this information with this method and then use this?
guidata(hObject, ...)

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!