How to use non-symmetric linewidth on a plot

Say I have the following:
upperbound = .001"
lowerbound = .003"
xdata = 1:.1:10
ydata = f(xdata)
I would like to plot(xdata,ydata) with a linewidth that is not symmetric. More specifically, I would like to have a shaded 'tube' with a maximum values of ydata + upperbound, and minimum values of ydata - lowerbound.
I've attached a picture to help explain what I'm trying to do. The only thing I would add is that I would like to have the space between the upper and lower bound shaded in.

 Accepted Answer

shadecolor = [.1 .2 .3];
fill([xdata, fliplr(xdata)], [ydata + upperbound, fliplr(ydata - lowerbound)], shadecolor);
So draw across the top, down to the bottom right, backwards across the bottom, automatically closes to original point.

2 Comments

Thanks for this response Walter! I didn't know about the fill command.
I'm still having some issues with my plot, but I think it's an issue with my data structure, and not the plotting method
Update for others reading my post: I managed to fix my issues by making the entities of my array horizontal (i.e. a 1xn array). Instead of using 'fill' I used 'patch' so I could plot one patch on top of another. I also needed to get rid of NaN entities from my arrays.
Thanks for your help Walter. You're awesome!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!