Clear Filters
Clear Filters

Export data from uicontrol objects in figures

4 views (last 30 days)
Hello!
In my script I have a figure with uicontrol objects in it (checkboxes, pop-outs and edit-text boxes). Once the user finishes entering all the data, there's an OK button, once hit, I want to save the data into an array + into an output file.
I have thought of creating a callback function behind the OK button, but then I have to send all this data into the function (and I'm not sure how..)
Another thing is that two of the checkboxes are for "save setting as default", so things have to be saved in few different places...
What would be a good way to do this?
Thank you so much for your help!

Answers (1)

Geoff Hayes
Geoff Hayes on 9 Aug 2015
Jasmine - have you used GUIDE to create your GUI? If so, you can use the handles structure to obtain the data from each of the controls. For all controls that you have created, there is a field for each in handles that has the handle for that control. So if you have a checkbox named checkbox1, then you could do
get(handles.checkbox1,'Value')
to get the Value property of this checkbox.
Now, since you have two places where you can save the data (either from the OK button or when you close the GUI), you could create a function within your GUI that both the OK button callback and the CloseFcn call to do all of the saving. Something like
function pushbutton1_Callback(hObject, eventdata, handles)
% call the function to save the data
saveData(handles);
function saveData(handles)
% open a file
% get the data from each property to save to file
cbValue1 = get(handles.checkbox1,'Value');
% etc.
% close the file

Categories

Find more on Migrate GUIDE Apps 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!