MATLAB Answers

Fill the region between two lines

조회 수: 859(최근 30일)
Hello all,
I plot two functions and then I want to fill the region between them in red (for example).
Could you please suggest me the function to do this?
Thanks
x=0:0.1:10;
y1=exp(-x/2);
y2=exp(-x/3);
figure
hold on
plot(x,y1)
plot(x,y2)

  댓글 수: 0

로그인 to comment.

채택된 답변

Star Strider
Star Strider 5 Feb 2019
Use the patch (link) function:
x=0:0.1:10;
y1=exp(-x/2);
y2=exp(-x/3);
figure
hold all
plot(x,y1)
plot(x,y2)
patch([x fliplr(x)], [y1 fliplr(y2)], 'g')
hold off
To use it, create a closed area (the reason for the fliplr calls, since they create the closed area), and choose the color.

  댓글 수: 0

로그인 to comment.

추가 답변(1개)

YT
YT 5 Feb 2019

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그


Translated by