Shade area under curve between two x values

조회 수: 10 (최근 30일)
pvtstaticvoid
pvtstaticvoid 2019년 1월 16일
답변: Robert U 2019년 1월 16일
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 ?

채택된 답변

Robert U
Robert U 2019년 1월 16일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by