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

non-singleton

for i=1:10201
SemivariancePredicSample_ST(i,:)=(GlobalSill-(T_x(1).*(1-exp(-(DistPredicSample_T.^2)/(T_x(2).^2)))+S_x(1).*(1.5*(DistPredicSample_S(i,:)/S_x(2))-0.5*(DistPredicSample_S(i,:).^3/S_x(2).^3)) ...
-((T_x(1)+S_x(1)-GlobalSill)/(T_x(1)*S_x(1)))*(T_x(1).*(1-exp(-(DistPredicSample_T.^2)/(T_x(2).^2)))).*(S_x(1).*(1.5*(DistPredicSample_S(i,:)/S_x(2))-0.5*(DistPredicSample_S(i,:).^3/S_x(2).^3)))))';
end
I get the error Assignment has more non-singleton rhs dimensions than non-singleton subscripts.
What to do?

Best Answer

Check for typos. This error occurs when the size of the left hand doesn't match the size on the right hand. (there are more dimensions that are not 1 (non-singleton) right hand side (rhs) than there are in the part of the array (the subscript) where you are trying to save it in)
The code below will trigger such an error, and here it is easy to see what is happening:
a=rand(4,4);
a(:,1)=rand(4,1,4);