Set listbox with excel content --Attempt to reference field of non-structure array

I have a GUI in which a want to set the content of an Excel file in a listbox, the code used is:
[ndata, text, alldata] = xlsread(filename);
set(handles.list_register,'String',cell2str(text));
The Excel file contains only one column with a string in each cell. Once the xls file is read the variable text is a cell type. When I compiled I got:
Attempt to reference field of non-structure array.
Error in Register>list_register_CreateFcn (line 100)
set(handles.list_register,'String',fields(struct(text)));
Thanks in advance for your help,

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 15 日
編集済み: Azzi Abdelmalek 2013 年 10 月 15 日

0 投票

cell2str is not a valid Matlab function, it's cellstr and the variable text is already a cell array

4 件のコメント

Manuel
Manuel 2013 年 10 月 15 日
Sorry you are right, anyway I am still having the same Problem with the code:
[ndata, text, alldata] = xlsread(filename);
set(handles.list_register,'String',text);
Any idea which could be the problem?
But the error message correspond to another line
set(handles.list_register,'String',fields(struct(text))
what struct(text) means?
Manuel
Manuel 2013 年 10 月 15 日
Sorry again I copied an old error, the erros is:
Attempt to reference field of non-structure array.
Error in Register>list_register_CreateFcn (line 100)
set(handles.list_register,'String',text);
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 15 日
Post the entire code for this callback

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

sixwwwwww
sixwwwwww 2013 年 10 月 15 日
Dear Manual, I assume that "text" just has one cell then you do like this:
[ndata, text, alldata] = xlsread(filename);
set(handles.list_register,'String',text{:});
I hope it helps

6 件のコメント

Manuel
Manuel 2013 年 10 月 15 日
編集済み: Manuel 2013 年 10 月 15 日
You are rigth is a cell, I used your Version but still give the same error:
Attempt to reference field of non-structure array.
Error in Register>list_register_CreateFcn (line 100)
set(handles.list_register,'String',text{:});
sixwwwwww
sixwwwwww 2013 年 10 月 15 日
Is your "text" contain any data? or is it empty? Also I agree with Azzi show us your code please
If text is a cell array
set(handles.list_register,'String',text);
is correct
Manuel
Manuel 2013 年 10 月 16 日
編集済み: Manuel 2013 年 10 月 17 日
This is the code:
function list_register_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
filename = fullfile('\\Data\Results\matlab','reg_list.xls');
[ndata, text, alldata] = xlsread(filename);
set(handles.list_register,'String',text);
Where text is:
text =
'11-Oct-2013---Start'
'03-Oct-2013---Modify'
'03-Oct-2013---Finish'
And type:
class(text)
ans =
cell
This is what I have and I got the error:
Attempt to reference field of non-structure array.
Error in Register>list_register_CreateFcn (line 100)
set(handles.list_register,'String',text);
Any idea how could I make it?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 16 日
Why your code is in function list_register_CreateFcn ? It should be in any callback
Manuel
Manuel 2013 年 10 月 16 日
編集済み: Manuel 2013 年 10 月 17 日
There is a button which opens a new GUI called Register, and when this Register is called then the listbox inside this Register needs to be created with text as content.
@Azzi Abdelmalek if you Need more data let me know.

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

質問済み:

2013 年 10 月 15 日

コメント済み:

2013 年 10 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by