Error: Attempt to reference field of non-structure array.

13 vues (au cours des 30 derniers jours)
JH
JH le 20 Sep 2011
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 commentaires
Walter Roberson
Walter Roberson le 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
JH
JH le 21 Sep 2011
Thank you Walter. I did see that question when googling the error, but I already checked to make sure that wasn't it. As you can see now in my edit, MATLAB gave a different error this time, which I can fix.
Apparently, it wanted vpa(int(...)) to convert the result into a double. I don't know why this initially resulted in the original error, but I'm just glad it threw an error I could fix.

Connectez-vous pour commenter.

Réponses (2)

Jan
Jan le 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?
  1 commentaire
JH
JH le 21 Sep 2011
I'm sorry I haven't posted the whole error yet. This is a terribly slow piece of code, but I don't know enough about what MATLAB can and can't to do to speed it up.
Everything functions until the line with the integration. I can plot Cls and Cl along y at different values of v and alpha no problem. When the error comes up, it only mentions the L(i,j)=...
As soon as it finishes running, I'll post the error again. The terrifyingly long running time would have been a tip off something was wrong, but I didn't notice last time, as I was at lunch.
I think it might be simply broken now. It's been running for almost 2 hours. And it is indeed stuck on the L(i,j)= line, and it has finished calculating everything before that point.

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 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.
  1 commentaire
JH
JH le 21 Sep 2011
That line is a direct copy from my code, and you can see that those are numbers, not letters. The int() function is symbolic integration.
http://www.mathworks.com/help/toolbox/symbolic/int-integral.html

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by