Matlab error: Argument to dynamic structure reference must evaluate to a valid field name.
Show older comments
I am doing a work for my class and in this equation:
t=(1./(4*ftab3*pi))*atan(sum(sin.(4*ti*ftab3*pi))/(sum(cos.(4*pi*ftab3*ti))));
it gives me this error :
Argument to dynamic structure reference must evaluate to a valid field name.
ftab3 is a matrix 82x2; ti is a vector 1:20
I don´t know if i have to change the vector ti, because is at my choise to give a value to vector ti.
3 Comments
Edison Peter
on 19 Feb 2020
Argument to dynamic structure reference must evaluate to a valid field name.
H_A1=(m+1)*Adet.*cosphi_A1.(m+1).*(2*pi.*D1*2);
Steven Lord
on 19 Feb 2020
cosphi_A1.(m+1)
If you're trying to index into a variable cosphi_A1 to extract element in location m+1 or call a function cosphi_A1 with m+1 as input, eliminate the period between the name and the parenthesis.
If you're trying to index into a struct array cosphi_A1 to retrieve the field whose name is m+1, m+1 has to return something that's a valid struct array field name. As an example the number 17 is not a valid field name, but "apple1" (formed if m was the string "apple" because of the way the + operator works when given a string and a number) would be.
>> cosphi_A1 = struct("apple1", 1980, "windows1", 1982);
>> m = "apple";
>> cosphi_A1.(m+1)
ans =
1980
Walter Roberson
on 21 Feb 2020
Perhaos cosphi_A1.*(m+1) was intended ?
Answers (1)
Walter Roberson
on 22 Oct 2015
0 votes
You have "sin." and "cos." . It appears that you should just have "sin" and "cos" with no "." part.
4 Comments
João Bernardo
on 22 Oct 2015
João Bernardo
on 22 Oct 2015
Walter Roberson
on 22 Oct 2015
I just tried it myself with just replacing the "." with space,
t=(1./(4*ftab3*pi))*atan(sum(sin (4*ti*ftab3*pi))/(sum(cos (4*pi*ftab3*ti))));
This does not complain that sin does not have enough input arguments. Not if you have managed to get that far by changing your variables to have matching dimension.
You have sin(4*ti*ftab3*pi) and you have cos(4*pi*ftab3*ti) . Your ti is a vector of arbitrary length (because you want to choose it to be arbitrary length), and your ftab3 is 82 x 2. What size of array are you expecting from ti*ftab3 (sin term) and are you expecting the size to be the same as for ftab3*ti (cos term) ? After you take the sin() or cos(), what size are you expecting the sum() to be?
With array values, the sum() is going to be an array or vector result. You are using the "/" operator, which is the "matrix right divide" operator. A/B is conceptually A*inverse(B) where "*" and "inverse" are algebraic matrix operations. Are you sure you want to be using a conceptual matrix inverse for "/" ? If you want to divide corresponding elements instead of doing algebraic matrix operations, you need to use ./ instead of using /
If you do have ti*ftab3 be the same size as ftab3*ti then the "/" operator would end up giving you a scalar, which you pass in to atan. When you see a division taking place within atan, you should be asking yourself whether instead of atan(A/B) if instead you should use atan(B,A) which is the full four-quadrant version of arctan. But which would operate element-by-element, so you would not be getting a scalar result.
Now you have 1./(4*ftab3*pi))*Something and the Something might possibly be a scalar, or might possibly be a vector, or possibly be a different size if ti*ftab3 is to be a different size than ftab3*ti . "*" is the Algebraic matrix multiplication operator so you need to know if the Something is either scalar or has inner dimensions that agree with the dimensions of ftab3 .
What output dimensions are you expecting anyhow?
João Bernardo
on 22 Oct 2015
Categories
Find more on Creating and Concatenating Matrices 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!