% empty out the final gradient matrix grad=[]; % in a for-loop, populate matrix one row at a time for i=1:256 % in a nested for-loop, populate matrix one column at a time for j=1:256 % the red channel increases with increasing rows (variable i) grad(i,j,1) = i; % the green channel increases with increasing columns (variable j) grad(i,j,2) = j; % the blue channel decreases with increasing rows (invert variable % i as 255-i) grad(i,j,3) = 255 - (i-1); end end % convert matrix to image data type and display image(uint8(grad));