Save and load edit box input data
16 views (last 30 days)
Show older comments
Hi everybody,
I made a simple gui for example and want to save and load the values in the edit text boxes. In the toolbar of the gui are a save and a load button. In this example, I have 7 edit text boxes. I get the handles, convert the handles into hex, save the new variable and do an easy calculation.
If I close the application I want to load the values I have saved earlier and display the values in the text boxes, so I don't need to fill them in again.
I want to create a kind of a preset that I can load/import for another code I've written.
I hope you get want I need.
Here is my simple code:
Thanks Max
function varargout = example(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @example_OpeningFcn, ...
'gui_OutputFcn', @example_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function example_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = example_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
edit1=str2double(get(hObject,'String'))*1000;
h1=dec2hex(edit1);
setappdata(0,'h1',h1);
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
edit2=str2double(get(hObject,'String'))*1000;
h2=dec2hex(edit2);
setappdata(0,'h2',h2);
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
edit3=str2double(get(hObject,'String'))*1000;
h3=dec2hex(edit3);
setappdata(0,'h3',h3);
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit4_Callback(hObject, eventdata, handles)
edit4=str2double(get(hObject,'String'))*1000;
h4=dec2hex(edit4);
setappdata(0,'h4',h4);
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit5_Callback(hObject, eventdata, handles)
edit5=str2double(get(hObject,'String'))*1000;
h5=dec2hex(edit5);
setappdata(0,'h5',h5);
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit6_Callback(hObject, eventdata, handles)
edit6=str2double(get(hObject,'String'))*1000;
h6=dec2hex(edit6);
setappdata(0,'h6',h6);
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit7_Callback(hObject, eventdata, handles)
edit7=str2double(get(hObject,'String'))*1000;
h7=dec2hex(edit7);
setappdata(0,'h7',h7);
function edit7_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
h1=getappdata(0,'h1');
h2=getappdata(0,'h2');
h3=getappdata(0,'h3');
h4=getappdata(0,'h4');
h5=getappdata(0,'h5');
h6=getappdata(0,'h6');
h7=getappdata(0,'h7');
X=h1+h2+h3+h4+h5+h6+h7;
% --------------------------------------------------------------------
function SaveButton_ClickedCallback(hObject, eventdata, handles)
% save the numbers the user put in the text boxes
% --------------------------------------------------------------------
function LoadButton_ClickedCallback(hObject, eventdata, handles)
% load the numbers and display them in the textboxes
5 Comments
Answers (0)
See Also
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!