Loading in to the POPUP menu of GUI
Show older comments
hello.. Is there a code to load a value to the popup menu from .mat file... there should be an option to select or change the data even after loading the value!!
Accepted Answer
More Answers (2)
Geoff Hayes
on 16 Feb 2015
Madhu - you can always reset the data in the popup menu by doing something like
set(handles.popupmenu1,'String',{'option a', 'option b', 'option c'});
The above line of code assumes that you have create a GUI using GUIDE and so have access to the handles structure and, in particular, the popup menu which is named popupmenu1.
If you wish to load some string options from a mat file, then you could do that as well. For example, suppose that we have created a mat file as
% create the cell array of string options
myOptions = {'A1','A2','A3'};
% save to a mat file
save('myOptions.mat','myOptions');
Then, in your GUI (perhaps the _OpeningFcn or in a callback) you would do the following
% load the data from the mat file
data = load('myOptions.mat','myOptions');
% update the popup menu
set(handles.popupmenu1,'String',data.myOptions);
Try the above and see what happens!
1 Comment
madhu T S
on 17 Feb 2015
Yoav Livneh
on 17 Feb 2015
Edited: Yoav Livneh
on 17 Feb 2015
You need to save and load the "Value" property of the popup menu. For example, taking Geoff Hayes's case:
% get the value from the popup menu
val = get(handles.popupmenu1,'value');
% save the data
save('selected_value.mat',val);
% load the data
val = load('selected_value.mat');
% update the popup menu
set(handles.popupmenu1,'value',val.val);
Categories
Find more on Workspace Variables and MAT Files 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!