Error: Cell contents reference from a non cell array object.

조회 수: 16 (최근 30일)
Monisha
Monisha 2014년 3월 2일
편집: John Kelly 2015년 2월 27일
I am using the following matlab code for selecting a particular row which matches a columnname from an access database. Once the row is retrieved , i try to store the values in a cell array .But i get an error when i try to print it.
q=FileNamevalue;
conn1=database('Dbname','','');
fna=exec(conn1,'select * from table1 where ImageName="',q,'"');
fna=fetch(fna);
fda=fna.data;
C = fda.'; %storing data in a cell array.
sprintf('ImageNo:%d\nImageName:%s\nDiseaseCategory: %s',C{1,1},C{2,1},C{3,1})
And here is the error: ??? Cell contents reference from a non-cell array object.
Error in ==> featurecomparison at 7 sprintf('IMAGENO:%d"\n"IMAGE NAME:%s"\n"DISEASE CATEGORY:%s"\n'); %Assumed to have 3 columns.
  댓글 수: 2
David Young
David Young 2014년 3월 2일
Please format your code using the {}Code button.
Image Analyst
Image Analyst 2014년 3월 2일
And you forgot to post your error message. Post ALL the red text . Don't snip out just part of it or paraphrase it, give us the whole thing.

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

답변 (3개)

Image Analyst
Image Analyst 2014년 3월 2일
What is the class of fda? Is it a cell array? What does this show if you put it just before the line that throws an error
whos fda
class(fda)
My guess is that fda is not a cell and so C is not a cell either, and then when you try to do C{1,1} it gives you the error because in order to use braces C must be a cell, which it is not .
  댓글 수: 13
Monisha
Monisha 2014년 3월 9일
@dpb @Image Analyst: I made another try using normal matlab cell operations and finally it worked. Sorry for not responding well and thanks for your valuable suggestions.
Image Analyst
Image Analyst 2014년 3월 9일
OK, well glad we could at least point you in the right direction.

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


dpb
dpb 2014년 3월 2일
Taking a chance with the crystal orb...
C = fda.'; %storing data in a cell array.
Excepting it isn't--you forgot the curlies...
C = {fda.'};
in which case it appears you might just as well have written
C={fna.data};

dpb
dpb 2014년 3월 8일
편집: John Kelly 2015년 2월 27일
...
fname=fetch(fname,10);
...
OK, from the database documentation for fetch one finds...
When fetch returns a cursor object, you can run many other functions, such as get and rows. To import data into the MATLAB workspace without metadata, use fetch with a database connection object as the input argument.
So, since we now know that fname is an object, we have to use the methods defined for that object.
See
and the links therefrom to get and joy should then ensue.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by