フィルターのクリア

Save variables in gui

3 ビュー (過去 30 日間)
Fiboehh
Fiboehh 2011 年 5 月 6 日
コメント済み: Jan 2018 年 2 月 13 日
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

採用された回答

Walter Roberson
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
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.
Jan
Jan 2018 年 2 月 13 日
@Walter: Replace:
guidata(handles)
by
guidata(hObject, handles)

サインインしてコメントする。

その他の回答 (1 件)

Fiboehh
Fiboehh 2011 年 5 月 7 日
I was too fast to accept the answer. I have a fault message when i try:
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);
this is the error message:
??? Error using ==> guidata at 89
H must be the handle to a figure or figure descendent.
Error in ==> DA>ls_Callback at 444
guidata(handles);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> DA at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)DA('ls_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
  1 件のコメント
Jan
Jan 2018 年 2 月 13 日
Replace:
guidata(handles)
by
guidata(hObject, handles)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by