MATLAB: Error :Assignment has more non-singleton rhs dimensions than non-singleton subscripts

rhs

I got this problem " Assignment has more non-singleton rhs dimensions than non-singleton subscripts " My code is:
v(m,i,j,k,l)=(-1*ones(m,i,j,k,l) + 2*rand(m,i,j,k,l))+rand*(gbest(m,i,j,k,l)-p(m,i,j,k,l));
Thank you so much!

Best Answer

ones(m,i,j,k,l) results in an m x i x j x k x l array. You compute something with that array size, and try to store the array result into the single scalar location v(m,i,j,k,l)
Related Question