Struct contents reference from a non-struct array object?

조회 수: 9 (최근 30일)
Philip Newell
Philip Newell 2016년 8월 19일
댓글: Steven Lord 2020년 9월 13일
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.

채택된 답변

Image Analyst
Image Analyst 2016년 8월 20일
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).

추가 답변 (1개)

PN Reddy
PN Reddy 2020년 9월 13일
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;

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by