hello ...i want to save the values entered in the editbox of matlab gui...

4 次查看(过去 30 天)
i want to save the values entered in the editbox of matlab gui such that whenever in future i open that program those value should be visible.......

回答(2 个)

Geoff Hayes
Geoff Hayes 2014-4-23
Hi Kiran,
A relatively simple solution would be to capture the event where the GUI/figure closes, grab any and all data that the user entered into the edit boxes, and write it to file. When the GUI opens, then read back that data from the file, and populate the edit boxes (or other widgets) as appropriate (if the file can't be found then just use default values). If using GUIDE, then something like the following code would be needed in your *.m file to write the data when the figure closes:
% --- Executes during object deletion, before destroying properties.
function figure1_DeleteFcn(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)
% open file to save data to
% grab data from widgets
% write data to file
% close file
Then in the same *.m file, in the code that fires just prior to the GUI being made visible, do the opposite:
% --- Executes just before yourGui is made visible.
function yourGui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled (see VARARGIN)
% open file to read data from
% read data and populate widgets
% close file
Hope that this helps!
Geoff
  3 个评论
Geoff Hayes
Geoff Hayes 2014-4-24
What does your code look like? Can you please post it? You will have to write the code to grab the data from the widgets (whichever they are) and write/save it to file (a *.mat file for example as Image Analyst mentions below) and then write the code to read the data from the file and then populate the widgets.

请先登录,再进行评论。


Image Analyst
Image Analyst 2014-4-23
I have functions SaveUserData() and LoadUserData().
SaveUserData reads the state or values in all the controls and puts their values into a structure called UserData. Then I save that to a mat file. I call this when I exit the app or sometimes when I do something major like change the data folder I'm working with.
LoadUserData reverses the process: it loads the structure from the mat file and then gets the control values/settings and sends them out to the various controls on the GUI. I put that in the OpeningFcn function.

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by