Struct contents reference from a non-struct array object?

8 ビュー (過去 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;
  1 件のコメント
Steven Lord
Steven Lord 2020 年 9 月 13 日
20.*x1.x2
You're missing an operator (my guess would be *) before x2.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by