Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
How to save actual values in a GUI to next session, simple example please
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I have a calculation that requires a large number of parameters to be entered and not expected to change all of them in each run, so I intent to save the last values used to next run. Im using version R2010a.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
%Función para almacenar los valores de los parámetros hasta la siguiente
%ejecución del código
saveState(handles)
delete(hObject);
function saveState(handles)
state.res_time=num2str(handles.res_timeTag);
state.max_rec_fin=num2str(handles.max_rec_fin);
state.max_rec_int=num2str(handles.max_rec_int);
state.max_rec_gru=num2str(handles.max_rec_gru);
save('var_values.mat','state')
function loadState(handles)
fileName='var_values.mat';
if exist(fileName)
load(fileName)
set(handles.res_timeTag,'string',state.res_time);
set(handles.max_rec_fin,'string',state.max_rec_fin);
set(handles.max_rec_int,'string',state.max_rec_int)
set(handles.max_rec_gru,'string',state.max_rec_gru)
delete(fileName)
end
thats the code Im actually using, together wit a call to loadState in OpeningFcn,
( I simply put it at the end, not know where to put it exactly, Im taking the idea from a video posted here http://blogs.mathworks.com/videos/2010/12/10/how-to-save-and-restore-state-of-a-gui-in-matlab/), I'm not using "get" to access the values for contruction of state, because this generates errors, this works partially but the values loaded change with no reason to me, in this form for r_max values
90 -> 239.0042
80 -> 240.0042
60 -> 241.0042
More than analyse my code, can you provide a very simple example how to do it.
2 Kommentare
Image Analyst
am 26 Mär. 2013
I think it's bad practice to delete the file right after you read it in. If you want to delete it, delete it right before you call save(), not after you call load.
Antworten (1)
Walter Roberson
am 26 Mär. 2013
What are handles.res_timeTag and so on? Are they uicontrol(), or are they values in the handle structure that you stored numeric data into? If they are uicontrol() then you should be using
state.max_rec_fin = get(handles.max_rec_fin, 'string')
and the like.
2 Kommentare
Image Analyst
am 26 Mär. 2013
what you saved was the handle itself, which will have a value like 239.0042. You did not save the value that the control with that handle had. For example, a slider may had a min of 1, a max of 100, a current value of 42, and handle of 239.0042. You need to "get" the property you want, for example the min, max, or value, and save THAT, NOT the handle value.
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!