Cell contents assignment to a non-cell array object.

2 views (last 30 days)
Hello everybody, I know that this error must be very common, but I have been trying to solve it for two days and I still can´t find the solution, I will try to explain it as fast as I can:
well at first, I had this error:
In an assignment A(I) = B, the number of elements in B and
I must be the same.
Error in ==> compic at 34
picad(i)= picaduradm(hb,vut,70,kr,dimens(11,i),dimens(11,i+3),dimens(2,i),dimens(2,i+3));
So, I was investigating it and I concluded that probably I was joining a scalar with a vector (It happened to me before), so I changed brackets () to {}, as follows:
picad{i}= picaduradm(hb,vut,70,kr,dimens(11,i),dimens(11,i+3),dimens(2,i),dimens(2,i+3));
And now I get this error:
Cell contents assignment to a non-cell array object.
Error in ==> compic at 34
picad{i}= picaduradm(hb,vut,70,kr,dimens(11,i),dimens(11,i+3),dimens(2,i),dimens(2,i+3));
If you need it, here you have the code of the function picaduradm:
function picadm = picaduradm(hb,h,revs,kr, dprim1, dprim2,z1,z2)%devuelve el esfuerzo admisible a picadura
ct=1;%factor de temperatura(no se esperan temperatures superiores a los 120ºC)
sc= ((hb*349)+34300)*0.006894759086775369;
N = revs*h*60;
if N<=10^4
cl=1.5;
elseif N>10^4 && N<=10^5
cl=1.3;
elseif N>10^5 && N<=10^6
kl=1.1;
else
cl=1;
end
if dprim1>dprim2 %este bucle comprueba si elengranaje comprobado es el más grande de la pareja para el calculo del ch.
m=z1/z2;
ch=1+(0.00069*(m-1));
else
ch=1;
end
picadm = (sc*cl*ch)/(ct*kr);
Thanks you very much.

Accepted Answer

per isakson
per isakson on 27 Apr 2013
Edited: per isakson on 27 Apr 2013
I assume
  • picaduradm returns a vector of doubles
  • picad is defined as a vector of doubles
Your assignments violate
  1. The vector returned by picaduradm cannot be assigned to an element of picad.
  2. The class of picad cannot be changed by an assignment to one of its elements, e.g to picad(i)
You need to have a look at "Getting started, Quick start" in the on-line help. Try to understand my examples below.
A = nan( 1, 4 );
B = rand( 1, 12 );
ix = 3;
A( ix ) = B;
A{ ix }
A{ ix } = B;
and the result (in red) in the command window
In an assignment A(I) = B, the number of elements in B and I must be the same.
Cell contents reference from a non-cell array object.
Cell contents assignment to a non-cell array object.
>>
However, defining new variables by assignments is ok
>> C = B
C =
Columns 1 through 10
0.9572 0.4854 0.8003 0.1419 0.4218 0.9157 <snip>
Columns 11 through 12
0.8491 0.9340
>> D{3} = B
D =
[] [] [1x12 double]
>>
and
>> E(2,:)=B
E =
Columns 1 through 10
0 0 0 0 0 0 <snip>
0.9572 0.4854 0.8003 0.1419 0.4218 0.9157 <snip>
Columns 11 through 12
0 0
0.8491 0.9340
.
Second thought:
  1 Comment
Jaime
Jaime on 27 Apr 2013
mmmm picaduradm returns a double (I suppose we can define it like 1 cell vector), but I did not define picad in the code: maybe that is the reason? I don´t have too much experience working with matlab, that´s the main problem. So what would you recomend me to do in this example?

Sign in to comment.

More Answers (1)

Jaime
Jaime on 27 Apr 2013
well, finally I solved it as follows:
picad(i)= str2double(picaduradm(hb,vut,70,kr,dimens(11,i),dimens(11,i+3),dimens(2,i),dimens(2,i+3)));
I must say, that I reached that conclusion after studying the examples isakson gave to me. Thanks you very much!

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!