Loading in to the POPUP menu of GUI
Afficher commentaires plus anciens
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!!
Réponse acceptée
Plus de réponses (2)
Geoff Hayes
le 16 Fév 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 commentaire
madhu T S
le 17 Fév 2015
Yoav Livneh
le 17 Fév 2015
Modifié(e) : Yoav Livneh
le 17 Fév 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);
Catégories
En savoir plus sur Workspace Variables and MAT Files dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!