Struct contents reference from a non-struct array object?
10 views (last 30 days)
Show older comments
Philip Newell
on 19 Aug 2016
Commented: Steven Lord
on 13 Sep 2020
I'm building a function to use as a moment condition for a GMM estimation. The package I intend to use requires a matrix of variables, so I used horzcat() to put together my data vectors. I've made the function using individual data vectors, but I get an error when trying to just call specific columns of my double array. Here's my code and error:
consumption = importdata('consumption_nonres_clean.mat');
leisure = importdata('leisure_nonres_clean.mat');
housing = importdata('housing_nonres_clean.mat');
pollution = importdata('pollution_nonres_clean.mat');
lhprice = importdata('lhprice_nonres_clean.mat');
lwage = importdata('lwage_nonres_clean.mat');
hprice = exp(lhprice);
wage = exp(lwage);
pie=.5;
mu=.5;
gamma=.5;
alpha_H=.5;
alpha_C=.5;
phi=-1;
psi=-1;
zeta=-1;
u = [pie mu gamma alpha_H alpha_C];
x = horzcat(consumption, housing, pollution);
y=hprice;
z=[phi, psi, zeta];
e = ( y(:) - ((u(1).u*(4))./(u(2).*u(5))).*((x(:,2).^(z(3)-1)).*(u(1).*x(:,2).^(z(3))+(1-u(1)).*x(:,3).^(-z(3))))./(x(:,1).^(z(1)-1).*(u(3).*x(:,1).^(z(1))+(1-u(3)).*x(:,3).^(-z(1)))));
Here's the error:
Struct contents reference from a non-struct array object.
Error in Untitled (line 24)
e = ( y(:) -
((u(1).u*(4))./(u(2).*u(5))).*((x(:,2).^(z(3)-1)).*(u(1).*x(:,2).^(z(3))+(1-u(1)).*x(:,3).^(-z(3))))./(x(:,1).^(z(1)-1).*(u(3).*x(:,1).^(z(1))+(1-u(3)).*x(:,3).^(-z(1)))));
I was trying to turn the double into a struct but it didn't seem to help.
0 Comments
Accepted Answer
Image Analyst
on 20 Aug 2016
You have this structure reference in there:
u(1).u*(4)
So it's expecting that u is a structure array, and the first structure in the array has a field (member) also called u. Well your u is not an array - it's just a normal 1-d numerical array. Please take a look at all dots, dot stars, dot slashes, dot carets, and parentheses to make sure you're doing every thing correctly. Like maybe you wanted u(1).*u(4) instead of u(1).u*(4).
More Answers (1)
PN Reddy
on 13 Sep 2020
Struct contents reference from a non-struct array object.
Error in fun (line 7)
fx=10*(x1-1)^2+20.*x1.x2+(x3-3)^2;
1 Comment
Steven Lord
on 13 Sep 2020
20.*x1.x2
You're missing an operator (my guess would be *) before x2.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!