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

2 views (last 30 days)
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.......

Answers (2)

Geoff Hayes
Geoff Hayes on 23 Apr 2014
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 Comments
Geoff Hayes
Geoff Hayes on 24 Apr 2014
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.

Sign in to comment.


Image Analyst
Image Analyst on 23 Apr 2014
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.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!