title: I am getting Issue of "incorrect number of subscripts on matrix"?
body: <p>I am getting problem of "incorrect number of subscripts on matrix" for long, Please help me. I am trying to find the bug  but unable to find, my data set is huge but i am using smaller initial data for program run.  I have tried my best but all in vain. The error comes in the last lines of code. I am new to coding so plz excuse my mistake in indentation. </p>
  
  <pre><code>########### inputs
  #Y &lt;- as.matrix(read.table("data2.dat"));
  #X &lt;- as.matrix(read.table("data1.dat"));
  ###########
  # smaller X and Y for initial code run.
  X &lt;- matrix(c(71,22,53,14,75,68,74,93,72),9,1)
  Y &lt;- matrix(c(7,1,4,1,7,6,6,8,5),9,1)
  
  
  
  ########### Constant
  Xlen &lt;- length(X[,1])  #### rows of X
  Yhat &lt;- as.matrix(mat.or.vec(Xlen,1))
  error &lt;- as.matrix(mat.or.vec(Xlen,1))
  Rmax &lt;- 30
  Z &lt;- as.matrix(cbind(X,Y)) 
  Zlen &lt;- length(Z[1,]) #### columns of Z
  P &lt;- as.matrix(mat.or.vec(1,Rmax))
  U &lt;- as.matrix(mat.or.vec(1,Rmax)) # mu calculation
  lambda &lt;- as.matrix(mat.or.vec(1,Rmax)) # lambda calculation
  C &lt;- as.matrix(mat.or.vec(Zlen,Rmax))
  R &lt;- 0
  sigma &lt;- 0
  beta &lt;- as.matrix(mat.or.vec(1,Zlen))
  Zp &lt;- mat.or.vec(1,Zlen)
  V1 &lt;- 0
  V2 &lt;- 0
  V3 &lt;- 0
  Pz &lt;- 0
  Dmin &lt;-0
  Dind &lt;-0
  Pmax &lt;-0
  Pind &lt;-0
  r &lt;- 0.4
  alpha &lt;- 4/(r^2)
  P_mat &lt;- 10^4 * diag(2)
  gamma &lt;- as.matrix(mat.or.vec(2,Rmax))
  w &lt;- as.matrix(mat.or.vec(2,Rmax))
  Xe &lt;- as.matrix(cbind(1,X))
  ##### 
  
  
  for (i in 1:Xlen)
  {   
  if (i==1) 
  {R &lt;- R+1 ; C[,R] &lt;- Z[i,] ; P[R] &lt;- 1; Yhat &lt;- Y[i,]}
  else 
  
  {V1 &lt;- sum(Z[i,]^2)
  sigma &lt;- sigma + sum(Z[i-1,]^2)
  beta &lt;- beta + Z[i-1,]
  V2 &lt;- sum(Z[i,]*t(beta))
  Pz &lt;- (i-1)/((i-1)*(V1+1)+(sigma-(2*V2)))
  for (j in 1:R)
  {V3 &lt;- sum((Z[i,]-Z[i-1,])^2);P[j] &lt;- ((i-1)*P[j])/((i-2)+(P[j])+(P[j]*V3))}
  dist &lt;- as.matrix(mat.or.vec(1,R))
  
  for (k in 1:R)
  {dist[k] &lt;- abs(sqrt(sum((Z[i,]-C[,k])^2)))}
  
  
  Dmin &lt;- min(dist)
  Dind &lt;- which.min(dist)
  
  
  Pmax &lt;- max(P)
  Pind &lt;- which.max(P)
  
  
  if (r &gt; Dmin/(1-(Pz/Pmax)) &amp;&amp; Pz &gt; Pmax)
  {C[,Dind] &lt;- Z[i,]; P[Dind] &lt;- Pz}
  
  if (r &lt; (Dmin/(1-(Pz/Pmax))) &amp;&amp; Pz &gt; Pmax &amp;&amp; R&lt; Rmax)
  {R &lt;- R+1; C[,R] &lt;- Z[i,]; P[R] &lt;- Pz}
  
  for(n in 1:R)
  {U[,n] &lt;- exp(-alpha*(X[i]-C[1,n])^2)}
  
  for(n in 1:R)
  {lambda[,n] &lt;- U[,n]/sum(U)}
  
  
  A1 &lt;- as.matrix(P_mat%*%Xe[i,]%*%lambda)
  B1 &lt;- as.matrix(t(lambda)%*%Xe[i,])
  C1 &lt;- as.matrix(diag(Rmax))
  D1 &lt;- as.matrix(P_mat)
  E1 &lt;- as.matrix(B1%*%D1%*%t(B1))
  F1 &lt;- C1+E1
  gamma &lt;- A1%*%solve(F1)
  P_mat &lt;- (diag(2)%*%gamma%*%t(lambda)%*%Xe[i,])%*%P_mat
  G1 &lt;- as.matrix(lambda%*%t(Xe[i,]%*%w))
  H1 &lt;- as.matrix(Y[i,])
  I1 &lt;- as.vector(H1-G1)
  J1 &lt;- I1*gamma
  w &lt;- w + J1; #as.matrix(I1%*%gamma)
  K1 &lt;- Xe[i,]%*%w
  L1 &lt;- lambda%*%t(K1)
  </code></pre>
  
  <p>here comes error at Yhat</p>
  
  <pre><code>Yhat[i,] &lt;- L1  
  #error[i,] &lt;- Y[i,]-Yhat[i,]
  #b &lt;- b+1
  }
  }
  #Yhat &lt;- as.vector(Yhat)
  #plot(Y,type="l",col="red")
  #lines(Yhat,col="green")
  #plot(Yhat)
  #plot(error)
  </code></pre>