Drawing a line to divide two parts of a curve

조회 수: 15 (최근 30일)
Nour BS
Nour BS 2021년 9월 15일
답변: Nour BS 2021년 9월 15일
Hello,
How can I draw a vertical line in a curve to divide two parts of the curve and color the first part?
Thanks in advance,

채택된 답변

Star Strider
Star Strider 2021년 9월 15일
Try this —
x = linspace(0, 20);
y = (1-exp(-0.1*x));
xq = 10;
yq = interp1(x,y,xq)
yq = 0.6321
figure
plot(x, y)
hold on
plot([1 1]*xq, [0 yq]) % Vertical Line
Lv = x<=xq;
patch([x(Lv) fliplr(x(Lv))], [zeros(1,nnz(Lv)) fliplr(y(Lv))], 'g', 'FaceAlpha',0.5) % Shaded ARea
hold off
Experiment with my code and your data
.

추가 답변 (2개)

Dave B
Dave B 2021년 9월 15일
편집: Dave B 2021년 9월 15일
You can draw a vertical line very easily with xline
area works well for filling a part of the curve
x=linspace(-3,3,100);
y=exp(-x.^2);
hold on
cutoff=.35;
area(x(x<cutoff),y(x<cutoff),'FaceAlpha',.2,'EdgeColor','none')
plot(x,y,'LineWidth',2)
xline(cutoff,'LineWidth',2,'Label',"The Value is " + cutoff,'LabelOrientation','horizontal')

Nour BS
Nour BS 2021년 9월 15일
THANK YOU VERY MUCH !! =D

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by