Using excel data for input into a pop up menu.

1 回表示 (過去 30 日間)
Christine Cunningham
Christine Cunningham 2016 年 2 月 15 日
コメント済み: Trick Verzosa 2016 年 8 月 19 日
[material_num, material_text, material_all] = xlsread('MaterialList.xlsx', 'B:B');
[value_num, value_text, value_all] = xlsread('MaterialList.xlsx', 'C:C');
[m,n] = size(material_text)
for x=1:m
string_list{x} = material_text(x,1)
end
set(handles.popupmenu1,'String', string_list)
currently I have this code above which takes words from an excel file and assigns the words into the variable string_list using a for loop. My problem is using string_list to input multiple words into the popup menu. Everytime I run this I get the error
Error using matlab.ui.control.UIControl/set
While setting the 'String' property of 'UIControl':
Cell arrays input to String property may only contain character and numeric matrices.
Error in SolderAngleGUI3>SolderAngleGUI3_OpeningFcn (line 62)
set(handles.popupmenu1,'String', string_list)
Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in SolderAngleGUI3 (line 42)
gui_mainfcn(gui_State, varargin{:});
I want the list to be made before my GUI appears so I currently have this code in the OpeningFcn of the GUI.
Are there problems with my code? Are they located in the correct function?

採用された回答

Walter Roberson
Walter Roberson 2016 年 2 月 15 日
When you use xlsread(), the second output is already a cell array of strings. You are using
for x=1:m
string_list{x} = material_text(x,1)
end
which indexes the cell array using array notation, which gives a cell array of size 1 rather than giving the content of the cell array. Therefor your string_list becomes a cell array of cell arrays of string.
You should use
string_list = material_text(1:m,1);
  4 件のコメント
Walter Roberson
Walter Roberson 2016 年 8 月 19 日
In that line, material_num and material_text and material_all are the variables that will receive the output of xlsread()
Trick Verzosa
Trick Verzosa 2016 年 8 月 19 日
I see. Thanks Walter!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by