Shade area under curve between two x values
조회 수: 10 (최근 30일)
이전 댓글 표시
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 ?
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Two y-axis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!