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

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 commentaires

Please format your code using the {}Code button.
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.

Connectez-vous pour commenter.

Réponses (3)

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 commentaires

In that case, Can i declare C explicitly like C={fda.'} and then try to access it?
Well, did you try it?
Why do you need it to be a cell and add the level of indirection anyway? Why not just use the (apparent) array directly?
I agree with dpb. We always try to avoid the complications and confusion of cells unless it's absolutely needed . By the way, why did you ignore my suggestions, or if you didn't, why did you not report back to us what it showed you?
@Image Analyst : Sorry for the delayed response . The following is the exact error in RED TEXT which i get on executing the code.
??? Cell contents reference from a non-cell array object.
promptMsg=sprintf('IMAGENO:%d"\n"IMAGE NAME:%s"\n"DISEASE CATEGORY:%s"\n'); %Assumed to have 3 columns.
Really bizarre. No line numbers or traceback? I'd definitely call the Mathworks on that because your error handler is not working correctly. Here's an example of what an error message might look like:
Undefined function or variable 'xclose'.
Error in test>calcmidpoints (line 31)
for n=1:length(xclose);
Error in test (line 8)
[midx,midy]=calcmidpoints(xclose,yclose);
See how it gives line numbers, etc.? In your code that you say the error is on, there are no braces so I don't see how that line can be the cause of a cell reference error.
Anyway, you're using sprintf and using %s in it but you're not supplying the things that are supposed to fill in for the %s. You need to pass in an integer and two strings just before the final ) of your sprintf call.
Monisha
Monisha le 3 Mar 2014
Modifié(e) : Monisha le 3 Mar 2014
??? Cell contents reference from a non-cell array object.
@Image Analyst: In a more precise context,I have attached the m file containing the code and the following error occurs:
Error in ==> featurecomparison at 12
promptMsg=sprintf('IMAGENO:%d"\n"IMAGE NAME:%s"\n"DISEASE CATEGORY:%s"\n"VIEW:%s"\n"GRADE:%s"\n"DESCRIPTION:%s"\n"PROXIMITY:%s"\n"SPECIALIZATION:%s"\n"SPECIALIST:%s"\n"TREATMENT:%s\n\n
Check the text
dpb
dpb le 3 Mar 2014
Modifié(e) : dpb le 3 Mar 2014
Well, you've not responded to the key point of what has been posted previously...
...
fname=fetch(fname,10);
fdata=fname.data;
%celldisp(fdata);
C = fdata.';
As previously asked, what's
whos fname fname.data
return? We've already (apparently) established that it's not a cell array and your assignment below doesn't turn it into one if it isn't. There's the whole nub of the problem but you're not really helping by not providing the requested information...
promptMsg=sprintf('IMAGENO:%d"\n ...
"IMAGE NAME:%s"\n ...
"DISEASE CATEGORY:%s"\n ...
"VIEW:%s"\n ...
"GRADE:%s"\n ...
"DESCRIPTION:%s" \n ...
"PROXIMITY:%s"\n ...
"SPECIALIZATION:%s"\n ...
"SPECIALIST:%s"\n ...
"TREATMENT:%s\n\n ...
Check the text file for further details ', C{:});
Now you've got a case where you need a numeric and 9(?) if I count correctly strings. Maybe it's a structure, not a cell array? But whatever, until we can see the details on that it's futile...
@dbp: fname is a cursor executing the query . fname.data is trying to fetch the data which the cursor fname executes.
dpb
dpb le 8 Mar 2014
Modifié(e) : dpb le 8 Mar 2014
What the blazes is a "cursor" in this context? I presume you mean it's the returned object from the database query; we already know that from the code you previously posted. What we don't know is what form the data within that object is store--I'm thinking since we now know about the database that it's likely a structure with named fields but specifically we can't tell what those are to know how to address them (or even for absolutely certain that my supposition is correct).
ADDENDUM: See the Answer posted somewhat later after I read the documentation. The supposition of fname being an object is correct and I learned what a cursor object is and how to access it from that page.
dpb, I suggest you take the comments to your answer so you can get credit for it. I've about given up on this one since I can't run her program to help with debugging it whereas you still seem interested in helping.
dpb
dpb le 8 Mar 2014
Modifié(e) : dpb le 8 Mar 2014
I thought I'd give one more try for her to actually answer the question.
I'm guessing fetch -- well, I suppose ought to go to the help--oh, I see. There is a different answer but OP surely could have gotten to it herself one would think. I'll post a new answer.
OBTW, your question asking for the class was spot on...it turns out she's getting another cursor object created.
@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.
OK, well glad we could at least point you in the right direction.

Connectez-vous pour commenter.

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 le 8 Mar 2014
Modifié(e) : John Kelly le 27 Fév 2015
...
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.

Produits

Question posée :

le 2 Mar 2014

Modifié(e) :

le 27 Fév 2015

Community Treasure Hunt

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

Start Hunting!

Translated by