GUI Popup Menu Import from excel header
Show older comments
I am using a popup menu and I want to pass that information from an excel document headers. The way the popup manu is formated it requires the text followed by comma ('text',).
% --- Executes during object creation, after setting all properties.
function popupmenu4_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
global data
for i = 1 : 1 : (length(data(1,:)))
var(1,i) = data(1,i);
end
set(hObject, 'String', {'Temperatures', 'Voltages', 'Currents', 'Speeds', 'Torques'});
How can I automate the pop up menus to auto populate from an excel header?
I have tried importing my headers into an array and passing the info to the call back function
like so:
filename = 'testGUI';
[num txt raw] = xlsread(filename,1);
for i = 1 : 1 : (length(raw(1,:)))
a(1,i) = raw(1,i);
end
and from there I tried to do as follows
set(hObject, 'String', {a});
But since it does not have the commas it does not recognizes all the elements of the array only the first one.
2 Comments
Adam
on 3 Jul 2018
for i = 1 : 1 : (length(raw(1,:)))
a(1,i) = raw(1,i);
end
What is the point of this loop? You might as well just use 'raw' straight away since 'a' is just an identical copy of it.
I don't know what format the third output of xlsread comes in, but
{a}
is definitely not going to give you anything you would want. It will simply put a into a one element cell array.
Guillaume
on 3 Jul 2018
As Adam said, all your loop does is:
a = raw(1, :); %and var = data(1, :); %for the other loop
so basically, give a meaningless variable name to something that had meaning. Also note that
length(raw(1, :))
is simply
size(raw, 2)
which involves less mental gymnastics in understanding.
Anyway, it's not clear what problem you're having. raw(1, :) should be a cell array of char arrays if the first row of your spreadsheet is indeed a header. In which case, why can't you pass that directly to the string property of your popupmenu?
Answers (0)
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!