Populating drop down gui from file
이전 댓글 표시
I created a Load Button which loads the excel file then I want to populate a pop up menu from column E of this file. How can I do that? Currently this give me an error
hload = uicontrol(f,'Style','pushbutton','String','Load Data',...
'Position',[380,260,70,25],...
'Callback',{@loadbutton_Callback});
hsubject = uicontrol(f,'Style','popupmenu',...
'String',{'Injury Level'},...
'Position',[5,260,100,25],...
'Callback',{@subjectpopup_menu_Callback});
%Each callback prompts user to select file to load and display.
function loadbutton_Callback(hObject, eventdata, handles)
disp('Hello 1');
[file] = uigetfile('.xlsx');
disp(file);
[num,txt,raw] = xlsread(file,'E2:E9');
disp(txt);
set(handles.Injury,'String',txt);
guidata(txt,handles.hsubject); %save data to gui
updateTable(txt); %update Table
end
채택된 답변
추가 답변 (1개)
Geoff Hayes
2017년 3월 24일
Yasaman - you didn't post your error message so we can only guess as to what might be the problem. You mention how you want to populate your popup menu with the data from the Excel file. The relevant code is
[file] = uigetfile('.xlsx');
[num,txt,raw] = xlsread(file,'E2:E9');
set(handles.Injury,'String',txt);
So you are trying to set the handles.Injury with the column E data. But what is this handle? Does it even exist? The popup menu that you create is
hsubject = uicontrol(f,'Style','popupmenu',...
and so the handle is hsubject. If this is the correct popup menu to update, then the code should be
[file] = uigetfile('.xlsx');
[num,txt,raw] = xlsread(file,'E2:E9');
set(hsubject,'String',txt);
You then call
guidata(txt,handles.hsubject); %save data to gui
which I don't understand. What are you attempting with this line? The signature for guidata is either
guidata(object_handle,data)
or
data = guidata(object_handle)
In either case, the first input parameter is an object handle. Usually, I wouldn't use guidata when creating a GUI programmatically so please clarify why you are using it here.
댓글 수: 2
Yasaman Best
2017년 3월 24일
Geoff Hayes
2017년 3월 24일
Did you try making the change that I suggested above? You may need to post all of your code so that we can get a better idea as to what you have written.
카테고리
도움말 센터 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!