Shade area under curve between two x values

13 views (last 30 days)
If I have a function, how do I shade the area underneath its graph between two x values? I've been using the area function, but it only lets me shade the area underneath the entire curve, which is not what I want.
For example, between to ?

Accepted Answer

Robert U
Robert U on 16 Jan 2019
Hi pvtstaticvoid:
You may define different intervals with area()-function. Using hold you can plot into the same axes as the function is plotted:
% define example function
f = @(x) x.^3;
% define plot intervals
plotInterval = -8:0.1:8;
areaInterval = 4:0.1:6;
% plot into one figure/axes
fh = figure;
ah = axes(fh);
plot(ah,plotInterval,f(plotInterval))
hold on
area(ah,areaInterval,f(areaInterval))
Kind regards,
Robert

More Answers (0)

Categories

Find more on Two y-axis in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!