MATLAB: How to shade the plot into different colors in MATLAB 7.9 (R2009b)

colorfillMATLABpatch

I am using the PLOT command to plot a few points like this:
figure,plot([0:0.1:1],[0:0.1:1])
hold on,plot(rand(10,1),rand(10,1),'*')
I am interested in seeing points above and below the X= Y line, and for this, I would like the top portion of this line to be colored red and the bottom portion to be colored blue.How can I do this?

Best Answer

In order to achieve this functionality, use the FILL command with the 'FaceAlpha' parameter in the following way:
figure,plot([0:0.1:1],[0:0.1:1])
hold on,plot(rand(10,1),rand(10,1),'*')
fill([0 1 0] , [0 1 1],'r','FaceAlpha',0.5) %Fill the top triangle red
fill([0 1 1] , [0 1 0],'b','FaceAlpha',0.5) %Fill the bottom triangle blue
To read more about the FILL command, please visit here: