user interface - How to access handles of another MATLAB GUI -


i have 2 guis in matlab. stored values in gui1 in handles structure, when displays in command window, looks this:

        gui1: [1x1 figure]         pushbutton2: [1x1 uicontrol]               text2: [1x1 uicontrol]               edit1: [1x1 uicontrol]              output: [1x1 figure]               val1: 0 

i want use val1 set value, counter, in gui2. don't have command initialize counter in gui2. how access handles of gui1 in gui2?

i tried use command guidata(findobj('tag', 'gui1')) handles, shows me it's empty.

i tried doing following:

in gui1, under openingfcn:

handles.val1 = 0; guidata(hobject, handles); setappdata(handles.gui1,'val1', handles.val1) 

and in gui2, in pushbutton function:

counter = getappdata(handles.gui1,'val1') 

but doesn't seem work either! gives me error saying, "reference non-existent field 'gui1'."

i have handle visibility on gui1, , tag set "gui1". why still having issue?

you should set gui's tag before finding object, i.e gui1's tag = gui1. can try find children of root object:

gui1_h = get(0,'children', 'tag', 'gui1'); 

or use findobj:

gui1_h = findobj('type', 'figure', 'tag', 'gui1'); 

in cases, gui's handlevisibility set off, in case, can use findall in gui2:

gui1_h = findall(0, 'type', 'figure', 'tag', 'gui1'); 

and handle struct:

data = guidata(gui1_h); disp(data.val); 

note opening 2 guis @ same time, if keep both guis' default tag figure1, gui1_h not counted graphic object's handle, hence cannot guidata.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -