Populating drop down gui from file
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Geoff Hayes
le 24 Mar 2017
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 commentaires
Yasaman Best
le 24 Mar 2017
Geoff Hayes
le 24 Mar 2017
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.
Catégories
En savoir plus sur Data Import from MATLAB 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!