Not sure what you're asking, but as you found out, the second way is correct. A color RGB image is a 3-D array with one color channel for red, one for green, and one for blue. Each color channel by itself is a 2-D image but when combined into an RGB image it becomes a 3-D array which takes 3 indexes, (row, column, colorChannelValue). To set a particular row and column to a value you have to use : and specify all three values
rgbImage(row, column, :) = [redValue, greenValue, blueValue];
Or you can do it one color channel at a time.
rgbImage(row, column, 1) = redValue;
rgbImage(row, column, 2) = greenValue;
rgbImage(row, column, 3) = blueValue;
But you can't do it like you did at first.