MATLAB: Save variables in gui

save variables gui

Dear, i'm strubling with the problem to save variables in a gui. I have an edit text with nothing in and when you type a number in it, i have to use this double in another widget or another function. I wrote http://matlab.wikia.com/wiki/FAQ?cb=4562#How_can_I_share_data_between_callback_functions_in_my_GUI.3F and tried the getappdata manner. So my callback function is like:
function ls_Callback(hObject, eventdata, handles)
% hObject handle to ls (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ls = str2double(get(hObject,'String')) %to convert to double
ls = getappdata(handles.ls ,'ls') % so i can save it?
save(sino,'ls') % gives fualt...
and to use it in another function i tried
sinopara = load(sino);
ls = sinopara.ls;
But it doesnt work, please please a understandeble solution 🙂 thx in advance

Best Answer

function ls_Callback(hObject, eventdata, handles)
% hObject handle to ls (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ls = str2double(get(hObject,'String')) %to convert to double
handles.ls = ls;
guidata(handles);
Then in any other callback or function that already had handles being passed to it, handles.ls would have the value. If you need the value someplace that does not have handles being passed to it, then
handles = guidata(YourFigureNumber);
and then use handles.ls
Related Question