title: Function 'subsindex' is not defined for values of class 'struct'
body: <p>I am using the matlab to solve a simple model in economics. But I came across an error </p>
  
  <p>Function 'subsindex' is not defined for values of class 'struct'</p>
  
  <p>when I run the last line of code. </p>
  
  <pre><code>omega=mkt_share(Par,w,Grid);
  </code></pre>
  
  <p>It appears wired to me as I call this function repeatedly in the code before reaching the last line, it works fine. Could anyone inform me how to solve the problem? Thanks!</p>
  
  <p>I post the full code of my program as following</p>
  
  <pre><code>clear all
  
  Par.theta = 1.5;
  Par.gamma = 6;
  Par.beta = 0.1;
  Par.zeta = 15;
  Par.n = 100;
  Grid.q = sort( gprnd(1/Par.zeta,1/Par.zeta,1,Par.n,1));
  Grid.q = Grid.q./Grid.q(1);
  
  
  w0=0.0001;
  We0=tot_mkt_share(Par,w0,Grid);
  mkt_share=mkt_share(Par,w0,Grid);
  w1=0.01;
  We1=tot_mkt_share(Par,w1,Grid);
  while(We0*We1&gt;0)
      if We0&lt;0 
          w0=w0*0.5;
          We0=tot_mkt_share(Par,w0,Grid);
      end
      if We1&gt;0
          w1=w1*1.5;
          We1=tot_mkt_share(Par,w1,Grid);
      end
  end
  iconv2=0;
  tol2=0.0000001;
  maxit2=1000;
  it2=1;
  while(iconv2==0 &amp;&amp; it2&lt;=maxit2)
      w=(w0+w1)/2;
      We=tot_mkt_share(Par,w,Grid);
      if abs(We)&lt;tol2
          iconv2=1;
          disp('wage has converged in')
          it2
      else
          if We*We1&gt;0
              w1=w;
          else
              w0=w;
          end
          it2=it2+1;
      end
  end
  if it2&gt;=maxit2
      disp('Warning: Zero profit condition not satisfied')
  end
  
  omega=mkt_share(Par,w,Grid);
  </code></pre>
  
  <p>The code for function mkt_share</p>
  
  <pre><code>function omega=mkt_share(Par,w0,Grid)
  
  omega=w0;
  
  for i=2:Par.n
      rel_q=Grid.q(i);
      fcn=@(omega) (rel_q)^(-Par.gamma)*(omega/w0)^(1-Par.beta*Par.gamma)*((1- 
      ((1-w0)/Par.gamma+w0/Par.theta))/(1- 
      ((1omega)/Par.gamma+omega/Par.theta)))^(Par.gamma-1)-1;
  
      omega_i=fsolve(fcn,w0);
      omega=[omega',omega_i]';
  
  end
  </code></pre>
  
  <p>The code for function tot_mkt_share, which calls function mkt_share</p>
  
  <pre><code>function tot_mkt_share=tot_mkt_share(Par,w0,Grid)
  
  tot_mkt_share=sum(mkt_share(Par,w0,Grid))-1;
  </code></pre>