I have two GUIs in MATLAB. I stored some values in GUI1 in the handles structure, so that when it displays in the Command Window, it looks like this:
GUI1: [1x1 Figure]
pushbutton2: [1x1 UIControl]
text2: [1x1 UIControl]
edit1: [1x1 UIControl]
output: [1x1 Figure]
val1: 0
I want to use val1
to set a value, counter
, in GUI2. I don't have any command to initialize counter
in GUI2. How do I access the handles of GUI1 in GUI2?
I tried to use the command guidata(findobj('Tag', 'GUI1')) to get those handles, but it shows me that it's empty.
I tried doing the following:
In GUI1, under OpeningFcn:
handles.val1 = 0;
guidata(hObject, handles);
setappdata(handles.GUI1,'val1', handles.val1)
And in GUI2, in a pushbutton function:
counter = getappdata(handles.GUI1,'val1')
But that doesn't seem to work either! It gives me an error saying, "Reference to non-existent field 'GUI1'."
I have the handle visibility on for GUI1, and a tag set to "GUI1". Why am I still having this issue?
counter=findobj('type','double')
, orcounter=findobj('type','double','parent',GUI1)
– Adiel