Save variables in gui
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Walter Roberson
2011-5-6
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
2 个评论
Walter Roberson
2011-5-6
By the way: the first thing that has to be passed to save() is a file name, but in your sample code you are passing an undefined variable.
save('sino','ls')
would have gotten you further, but your getappdata() call is incorrect so you probably would have ended up saving an empty matrix.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!