Shade area under curve between two x values

12 Ansichten (letzte 30 Tage)
pvtstaticvoid
pvtstaticvoid am 16 Jan. 2019
Beantwortet: Robert U am 16 Jan. 2019
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 ?

Akzeptierte Antwort

Robert U
Robert U am 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

Weitere Antworten (0)

Kategorien

Mehr zu Two y-axis finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by