Loading in to the POPUP menu of GUI
이전 댓글 표시
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!!
채택된 답변
추가 답변 (2개)
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!
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);
카테고리
도움말 센터 및 File 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!