MATLAB: How to color an area at plot surface…

plot color

How can i color the area between 2 functions like
f(x)=x^2
g(x)=-x^2+1

Best Answer

I found a better way... try
x=1:10;
f=x.^2;
g=x.^2+1;
patch([x x(end:-1:1)], [f g(end:-1:1)],'y')
This sets up x=1...10, g=x² and f=x²+1 and then plots the area between the curves as a yellow polygon/patch. Compare the matlab help for patch.
Here i simply draw all points forf first in positive x direction and then jump to the last point of g and draw the points of g backwards from x=10...1. All in all a complete polygon. Btw, 'y' is the color yellow.