Save variables in gui

2 visualizaciones (últimos 30 días)
Fiboehh
Fiboehh el 6 de Mayo de 2011
Comentada: Jan el 13 de Feb. de 2018
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de Mayo de 2011
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 comentarios
Walter Roberson
Walter Roberson el 6 de Mayo de 2011
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 el 13 de Feb. de 2018
@Walter: Replace:
guidata(handles)
by
guidata(hObject, handles)

Iniciar sesión para comentar.

Más respuestas (1)

Fiboehh
Fiboehh el 7 de Mayo de 2011
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 comentario
Jan
Jan el 13 de Feb. de 2018
Replace:
guidata(handles)
by
guidata(hObject, handles)

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by