MATLAB: How to fade colors into each other

matrix manipulation

I'm trying to get red in the top right, purple in the top left, blue in the bottom right, and green in the bottom left. However, instead of fading together the colors are staying separate of each other. What am I doing wrong?
r=256;
c=256;
d=3;
A=zeros(r,c,d);
increase=linspace (0,1,256);
decrease= linspace (1,0,256);
%Top

for i=1:256
%Top
A(1:128,i,1)=1;
A(1:128,i,3)=increase(i);
%Bottom
A(128:256,i,3)=increase(i);
A(128:256,i,2)=decrease(i);
end
imagesc(A)
I add the following into my for loop: %left
A(i,1:128,1)=decrease(i);
A(i,1:128,2)=increase(i);
%right
A(i,128:256,1)=decrease(i);
A(i,128:256,3)=increase(i);
Now I get a weird triangle thing, what am I doing wrong? I want all of them to fade into each other.

Best Answer

Try this:
rows = 256;
oneColumn = ((rows-1) : -1 : 0)';
redChannel = uint8(repmat(oneColumn, [1, rows]));
blueChannel = uint8(toeplitz((rows-1):-1:0));
greenChannel = uint8(toeplitz(0:(rows-1)));
triangleMask = logical(triu(ones(rows, rows)));
greenChannel(triangleMask) = 0;
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
imshow(rgbImage);