Getting value from a listbox. Error: Cell contents reference from a non-cell array object.

조회 수: 1 (최근 30일)
Im trying to get the value selected in a listbox(Temp_listbox) by a callback botton and the listbox contains cells of integers:
string5 = get(handles.Temp_listbox, 'String');%%get cond1
value5 = get(handles.Temp_listbox, 'Value');
cond1 = string5{value5};
But I got the error: Cell contents reference from a non-cell array object.
Any idea about how could be solved? Thanks in advance.
Note: The value of cond1 is used afterwards to find the intersection in an array and plot the data.
  댓글 수: 2
David Sanchez
David Sanchez 2013년 8월 23일
Are you sure this error message makes reference to these lines of code? They seem all right and should not yield an error.
Manuel
Manuel 2013년 8월 23일
I think so, the error is :
Cell contents reference from a non-cell array object.
Error in GUI_v1>plot1_Callback (line 405)
cond1 = string5{value5};
And in the same callback function I have also similar code but for other listboxs and is working correctly :
string3 = get(handles.listchip_version, 'String');%%get chip version
value3 = get(handles.listchip_version, 'Value');
chip1 = string3{value3};
string4 = get(handles.listtest, 'String');%%get test version
value4 = get(handles.listtest, 'Value');
test1 = string4{value4};
The only different in the cond1 is the content of the listbox which one is a number and not a string value.

댓글을 달려면 로그인하십시오.

채택된 답변

Grzegorz Knor
Grzegorz Knor 2013년 8월 23일
I suppose that your listbox contains only one string. Compare two codes:
1:
lb = uicontrol('Style','listbox','Position',[10 10 100 100],'String','a');
a = get(lb,'String');
a{get(lb,'Value')}
2:
lb = uicontrol('Style','listbox','Position',[10 10 100 100],'String',{'a','b','c'});
a = get(lb,'String');
a{get(lb,'Value')}
Code 1 produces an error.
  댓글 수: 3
Walter Roberson
Walter Roberson 2013년 8월 23일
Also watch out for the case where the String property is empty.
If you are not absolutely positive that the String property will be cell array, then cellstr(get(TheHandle, 'String'))
At one point in an old Answer, I listed the conditions under which the String property would not be a cell array.
Manuel
Manuel 2013년 8월 26일
Hello Walter, you are right when the string property is empty does not work, with
cellstr(get(TheHandle, 'String'))
works perfect.
Thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

ES
ES 2013년 8월 23일
Not sure, you must be doing something wrong. It works fine,
if true
eg:
set(handles.listbox1, 'String',{1,2,3,4})% to set set of integers as entries for the list box.
and somewhee else,
string5 = get(handles.listbox1, 'String');%%get cond1 value5 = get(handles.listbox1, 'Value'); cond1 = string5{value5};
output is cond1=1 end
please check..
  댓글 수: 1
Manuel
Manuel 2013년 8월 23일
I check and the error is still there :
Cell contents reference from a non-cell array object.
Error in GUI_v1>plot1_Callback (line 405)
cond1 = string5{value5};
And in the same callback function I have also similar code but for other listboxs and is working correctly :
string3 = get(handles.listchip_version, 'String');%%get chip version
value3 = get(handles.listchip_version, 'Value');
chip1 = string3{value3};
string4 = get(handles.listtest, 'String');%%get test version
value4 = get(handles.listtest, 'Value');
test1 = string4{value4};
The only different in the cond1 is the content of the listbox which one is a number and not a string value.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by