Loading in to the POPUP menu of GUI

조회 수: 4 (최근 30일)
madhu T S
madhu T S 2015년 2월 16일
편집: madhu T S 2015년 2월 23일
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!!

채택된 답변

madhu T S
madhu T S 2015년 2월 23일
편집: madhu T S 2015년 2월 23일
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

추가 답변 (2개)

Geoff Hayes
Geoff Hayes 2015년 2월 16일
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
madhu T S
madhu T S 2015년 2월 17일
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

댓글을 달려면 로그인하십시오.


Yoav Livneh
Yoav Livneh 2015년 2월 17일
편집: Yoav Livneh 2015년 2월 17일
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);

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by