Your opengl turns out to not be relevant to this.
You have a 2d or 3d array. You are assigning into the array using a single subscript, so that means you are using linear indices. Some of the target indices being assigned to are larger than the number of elements in the array, so MATLAB needs to grow the array. But which dimension should it grow the array on? Add more rows? Add more columns? Add more to the third dimension? Start into the next dimension beyond the existing ones? MATLAB does not have a rule for which dimension to expand when you attempt to assign to a linear index beyond the end of an array that is not a vector (vector is well defined for this) so it gives you the ambiguous dimension error.
If you are deliberately expanding the matrix then translate the linear indices into row and column references so that MATLAB can see which dimension is being grown.