Error: Attempt to reference field of non-structure array.
13 views (last 30 days)
Show older comments
Hi, I'm trying to figure out why I'm getting this error in my code. Here's my code, and underneath is an explanation of what it does. v=.25:.25:40; T, Rev, J, Cp, Ct, n, H, Vbar, vs and Rw are all functions of v, so they're arrays too. Here's where it gets complicated.
syms y;
Aa=(32.*(Cp./(2*pi)).*(1-Ct).^.5./(pi.*J.^2.*(1.+(1.-Ct./(1.-Ct))))).*y./Rw;
c=1.2954.*heaviside(.038815-y)+(((1.524./2).^2-(y+.5).^2).^.5).*heaviside(y-.038815);
So there's that, which represents a variable Aa depending on y, valid from -Rw<y<Rw at whatever v is being used at the moment. C however, goes from quite a bit less than -Rw to just a bit above Rw.
Then I try to calculate my lift coefficients. Cls is for -Rw to Rw and Cl includes the part of the wing outside that. There's two for loops iterating through v and alpha outside of these.
Cls=vpa((6.02293*sin(alpha(i))/2*(1+4/pi*(1.688466196366/c)*(1-((.5+y)/(1.52401))^2)^.5)*(1/2*1.185*v(j)^2)/(1/2*1.185*vs(j)^2)+1.87*(Rw(j)/c)*(1-(v(j)/vs(j))^2)*(0-Aa(j))/(pi^2/4-1)*(1/(y/Rw(j))-(y/Rw(j)))*log((1+y/Rw(j))/(1-y/Rw(j)))));
Cl=6.02293*alpha(i)*heaviside(-(Rw(j)+y))+Cls*(heaviside(Rw(j)-y)*heaviside(Rw(j)+y))+6.02293*alpha(i)*heaviside(y-Rw(j));
My problem comes after this. I need to integrate 1/2*1.185*v^2*c*Cl from -.5 to .262, which is the span of the wing.
L(i,j)=2*int(1/2*1.185*v(j)^2*c*Cl,y,-.5,0.262005);
This line is what gives me the error. I don't know why, and I'm getting annoyed at this program. So if anyone has any advice on how to fix it, or perhaps simplify my code so I never need to do whatever causes the error, I would be grateful.
Thank you.
EDIT: Good News/Bad News. The error is gone, replaced by a different error that I do know what means. Unfortunately, it takes near 3 hours to perform one of a couple thousand calculations. So. I could use help optimizing the code to run faster, if anyone would like to volunteer.
3 Comments
Walter Roberson
on 21 Sep 2011
Someone had a very similar problem a week ago; see http://www.mathworks.com/matlabcentral/answers/15793-attempt-to-reference-field-of-non-structure-array
Answers (2)
Jan
on 20 Sep 2011
I'm getting nervous when I see constructs like ".^.5./". They make me start to think, and thinking is prone to errors. I strongly suggest to use 0.5 instead of .5 and insert spaces around the operators to avoid ambiguities.
Are you sure, that there is no lowercase L instead of a 1 (one)?
Does the error appear in the posted line, or inside the INT command?
Image Analyst
on 21 Sep 2011
Since this line
L(i,j)=2*int(1/2*1.185*v(j)^2*c*Cl,y,-.5,0.262005);
is what throws the exception, and structure members are to the right of dots, I'd say that it thinks either 185 or 262005 is a member of a structure, so it must think 1 or 0 is a variable. Like Jan said, are you sure it's a one and not the lower case letter L and a zero and not the letter O?
Finally, I don't know what int() is. Are you sure it takes 3 arguments? Did you mean int32()? For int() it says this, which I don't understand:
int
int Convert a FILTSTATES.CIC object to an integer matrix.
int(Hs) returns an signed integer matrix for the FILTSTATES.CIC
object.
EXAMPLE:
Hm = mfilt.cicdecim;
hs = Hm.states; % Returns a FILTSTATES.CIC object
states = int(hs); % Convert object to a signed integer matrix.
See also
FILTSTATES/CIC.
I have no idea what a "FILTSTATES.CIC object" is.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!