赋值具有比非单例下标更多的非单例rhs维度

时间:2017-05-12 10:11:19

标签: matlab matrix

我正在尝试编写GMM功能。问题是,对于下一个循环,我得到下一个错误:

Assignment has more non-singleton rhs dimensions than non-singleton subscripts.

错误与此处开始的循环部分有关。在循环下面你有整个代码。我在互联网上搜索,我尝试了很多东西,但我真的不明白为什么我有这个问题。我还检查了包含的每个变量的大小,它们都是(694,1),我很确定指定的每个变量的大小都是正确的。

% 
for i=1:T-3      
         % g(i,1)=((beta.*((c1(i).^(-alpha)) + (b*beta*(c2(i)).^(-alpha))).*dj(i)) - (b*beta.*(c1(i)).^(-alpha))) - 1;
          a(:,i)=(((beta.*((c1(i).^(-alpha)) + (b*beta*(c2(i)).^(-alpha))).*dj(i)) - (b*beta.*(c1(i)).^(-alpha))) - 1);
          b(:,i)=(((beta.*((c1(i).^(-alpha)) + (b*beta*(c2(i)).^(-alpha))).*dj(i)) - (b*beta.*(c1(i)).^(-alpha))) - 1)*dj(i);      
          c(:,i)=(((beta.*((c1(i).^(-alpha)) + (b*beta*(c2(i)).^(-alpha))).*dj(i)) - (b*beta.*(c1(i)).^(-alpha))) - 1)*consumpt(i);


%     function [q] = Q(param,M,data,cond)

   T = length(data);

  % Population moments
  % [PMvec] = populat0ion_moments(param);
   %sigma = param(2);  
   alpha = param(1);
   beta = param(2);
   b = param(3);
  % c = ( data(3:end,1) + b*(data(2:end-1,1)))./(data(2:end-1,1) + b*(data(1:end-2,1) + b*( data(3:end,1)) + b*(data(2:end-1,1))./(data(2:end-1,1) + b*(data(1:end-2,1)));
   dj= data(2:end-2,2)./data(1:end-3,2);
   cpr = data(1:end-3,1) 
   ctd = data(2:end-2,1)
   ctw = data(3:end-1,1)
   ctw2= data(4:end, 1)

   c1 = (ctw+b.*ctd)./(ctd+b.*cpr);   
   c2 = (ctw2+b.*ctw)./(ctd+b.*cpr);


    consumpt = data(2:end-2,1)./data(1:end-3,1);
   [row,col] = size(cpr);
      djinst = dj(1:row,1);
   %z = [1 consumpt djinst]

    a = zeros(1, 694);
    b = zeros(1, 694);
    c = zeros(1, 694);
   for i=1:T-4

         % g(i,1)=((beta.*((c1(i).^(-alpha)) + (b*beta*(c2(i)).^(-alpha))).*dj(i)) - (b*beta.*(c1(i)).^(-alpha))) - 1;
          a(:,i)=(((beta.*((c1(i).^(-alpha)) + (b*beta*(c2(i)).^(-alpha))).*dj(i)) - (b*beta.*(c1(i)).^(-alpha))) - 1);

          b(:,i)=(((beta.*((c1(i).^(-alpha)) + (b*beta*(c2(i)).^(-alpha))).*dj(i)) - (b*beta.*(c1(i)).^(-alpha))) - 1)*dj(i);

 c(:,i)=(((beta.*((c1(i).^(-alpha)) + (b*beta (c2(i)).^(-alpha))).*dj(i)) - (b*beta.*(c1(i)).^(-alpha))) - 1)*consumpt(i);

我收到以下错误:

Assignment has more non-singleton rhs dimensions than non-singleton subscripts 

Error in Q (line 43) 

 a(:,i)=(((beta.*((c1(i).^(-alpha)) + (bbeta*(c2(i)).^(-alpha))).*dj(i)) - (bbeta.*(c1(i)).^(-alpha))) - 1);

1 个答案:

答案 0 :(得分:0)

看起来您正在将b从标量重新分配给向量,这可能会导致问题。

b = param(3);
...
b = zeros(1, 694);