How to fill the region formed by four lines?

조회 수: 6 (최근 30일)
Tmat
Tmat 2022년 11월 30일
댓글: Tmat 2022년 11월 30일
I want to fill the parallelogram region formed by four straight lines. I have tried the following codes:
beta11_um1 = @(delta11) 4.1797+0.396*delta11;
beta11_lm1 = @(delta11) 0.4090+0.396*delta11;
beta11_up1= @(delta11) 3.8058-0.475*delta11;
beta11_lp1= @(delta11) 1.916-0.475*delta11;
delta11= -10:0.1:10;
pgon1 = polyshape(delta11,beta11_um1(delta11));
pgon2 = polyshape(delta11,beta11_lm1(delta11));
pgon3= polyshape(delta11,beta11_up1(delta11));
pgon4= polyshape(delta11,beta11_lp1(delta11));
figure
plot(delta11,beta11_um1(delta11),delta11,beta11_lm1(delta11),delta11,beta11_up1(delta11),delta11,beta11_lp1(delta11));
hold on
plot(intersect(pgon1,pgon2,pgon3,pgon4),'EdgeColor','none','FaceColor','m')
The output of the codes do have the four lines plotted, but the parallelogram region in the middle is not filled. How could I fix this? Thanks!

채택된 답변

David Hill
David Hill 2022년 11월 30일
편집: David Hill 2022년 11월 30일
beta11_um1 = @(delta11) 4.1797+0.396*delta11;
beta11_lm1 = @(delta11) 0.4090+0.396*delta11;
beta11_up1= @(delta11) 3.8058-0.475*delta11;
beta11_lp1= @(delta11) 1.916-0.475*delta11;
delta11= -10:0.1:10;
figure
plot(delta11,beta11_um1(delta11),delta11,beta11_lm1(delta11),delta11,beta11_up1(delta11),delta11,beta11_lp1(delta11));
x=[-2.598967,1.730195,3.899885,-.429277];
y=[beta11_lp1(x(1)),beta11_lp1(x(2)),beta11_up1(x(3)),beta11_up1(x(4))];
pgon=polyshape(x,y);
hold on;
plot(pgon,'EdgeColor','none','FaceColor','m')
  댓글 수: 3
David Hill
David Hill 2022년 11월 30일
beta11_um1 = @(delta11) 4.1797+0.396*delta11;
beta11_lm1 = @(delta11) 0.4090+0.396*delta11;
beta11_up1= @(delta11) 3.8058-0.475*delta11;
beta11_lp1= @(delta11) 1.916-0.475*delta11;
x=[fzero(@(x)beta11_um1(x)-beta11_lp1(x),1),...
fzero(@(x)beta11_lm1(x)-beta11_lp1(x),1),...
fzero(@(x)beta11_lm1(x)-beta11_up1(x),1),...
fzero(@(x)beta11_um1(x)-beta11_up1(x),1)]
x = 1×4
-2.5990 1.7302 3.8999 -0.4293
Tmat
Tmat 2022년 11월 30일
@David Hill Thanks, David! This is very helpful. One last question: how to show the legends of these equations on the graph too?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by