Loading in to the POPUP menu of GUI

2 visualizzazioni (ultimi 30 giorni)
madhu T S
madhu T S il 16 Feb 2015
Modificato: madhu T S il 23 Feb 2015
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!!

Risposta accettata

madhu T S
madhu T S il 23 Feb 2015
Modificato: madhu T S il 23 Feb 2015
hello Yoav Livneh and Geoff Hayes.. thanks for your valuable comments.. I somehow got the answer for the above question and I wud like to share with you ppl..
I have 5 options in the POPUP menu as awake sleeping waiting in gym out
we have to compare the data got from the .mat file and then change the value property according to it. he I'm sharing my code of load push button..
call back function of pushbutton will look like below
function load_pb_Callback(hObject, eventdata, handles) [filename pathname] = uigetfile('*.mat','Select the MATLAB code file'); L = load( fullfile( pathname, filename ) ); varnames = fieldnames(L); % Message=num2str(L.(varnames{1})); Status= num2str(L.(varnames{2})); if strcmp(Status,'awake') set(handles.popup,'value', 1) elseif strcmp(Status,'sleeping') set(handles.popup,'value', 2) elseif strcmp(Status,'waiting') set(handles.popup,'value',3) elseif strcmp(Status,'out') set(handles.popup,'value', 5) elseif strcmp(Status,'in gym') set(handles.popup,'value', 4) end
regards madhu

Più risposte (2)

Geoff Hayes
Geoff Hayes il 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 Commento
madhu T S
madhu T S il 17 Feb 2015
Hi Geoff Hayes... thank you very much for your response.. I think I was not clear in my question... let me make it clear
considering your example... the handles of popupmenu1 will be updated with 'option a', 'option b', 'option c', then I will select any one of those and save in the data.mat file with tag name text_popupmenu1... when I want to load the data.mat file sometime later it will load only the saved one in to the string of the popupmenu... now my point is, can I have a provision to select the other two too with the loaded option after loading with some pushbutton

Accedi per commentare.


Yoav Livneh
Yoav Livneh il 17 Feb 2015
Modificato: Yoav Livneh il 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);

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by