fill problem--shading the wrong parts of a curve
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Sean de Wolski
on 11 Sep 2012
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.
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!