You need to define 3 components as you mentioned: R, G, B. Also if you want to work with color channels as integers 0..255, you need to convert the matrix type to integer:
img = ones(256,256,3) * 255; % 3 channels: R G B
img = uint8(img); % we are using integers 0 .. 255
% top left square:
img(1:20, 1:20, 1) = 255; % set R component to maximum value
img(1:20, 1:20, [2 3]) = 0; % clear G and B components
% top right square:
img(1:20, 237:256, [1 3]) = 0; % clear R and B components
img(1:20, 237:256, 2) = 255; % set G component to its maximum
% bottom left square:
img(237:256, 1:20, [1 2]) = 0;
img(237:256, 1:20, 3) = 255;
% bottom right square:
img(237:256, 237:256, [1 2 3]) = 0;
imshow(img);
Hope it helps you to get the idea.