MATLAB: Fill problem–shading the wrong parts of a curve

fill

I'm having trouble using fill to shade the area between two curves. The code I'm using is
fill(x,[y1 y2],'k')
I've also tried
fill([x x],[y1 y2],'k')
which gives the same result. Is there something obvious I'm missing? Below is the plot I'm getting. I'd like to shade the are between the two curves, not between the first and last y value of each curve. Ideas?

Best Answer

And there is a problem we all run into the first time we use fill() :)
x = 1:10;
y1 = rand(1,10)+1;
y2 = rand(1,10)-0.5;
fill([x fliplr(x)],[y1 fliplr(y2)],'c')
The sorting order is important. You want to trace the outside as if you were to walk around your x/y coordinates.