MATLAB: Retrieving data from a gui

gui

Hello everybody.
I am new user of GUi and have a maybe stupid question. I have a main program from which I call a gui created with guide. From this Gui function (called button_ter), I would like to retrieve de data of one of the callback to use it in the main program. Here is the part written in the gui (with guide) from which I would like to extract the "lambda" value:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

uicontrol(hObject)
uiresume;
close(handles.figure1)
%delete(hObject.figure1);
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.lambda = str2double(get(hObject,'String'))
varargout{2}=handles.lambda
guidata(hObject,handles)
%handles = guidata(handles.lambda);
setappdata(handles.edit1,'lambda',varargout{2})
I tried to retrieve the data from the main program with "getappdata" in this main program but it doesn't work. After looking a lot on matlab help,I've tried many things… test=getappdata(@edit1,lambda) test=getappdata(@button_ter,lambda) test=getappdata(@button_ter,edit1)
but none worked. What I do not understand is that the data seems to be correctly generated in my gui code because I see this on the prompt:
handles =
figure1: 173.0016
edit1: 4.0017
text3: 3.0017
text2: 2.0017
pushbutton1: 1.0017
uitable1: 0.0017
text1: 174.0016
output: 173.0016
lambda: 45
varargout =
[] [45]
but after that, either it writes -Undefined function or variable -or Conversion to double from function_handle is not possible.
I'm sure I forgot something stupid in the command line from my main program.
But What? Does anyone have an idea for me?
Thanks a lot.
Scilla

Best Answer

THANKS!!!! it works!
but I do not understand. I thought the "setappdata" just to do what you mention: store lambda even if I close the button.
so I do not understand the difference between setappdata/getappdata and set/get. Other stupid question: the "0" in the set and get is a value for the handle is that right? I was confused by this handle because I tried (as you can see in my "setappdata") to put a string and not a value.
Thanks a lot once again. I spent so many time to grab these gui things...
Related Question