Shade an area between 5 lines

조회 수: 6 (최근 30일)
tom thornton
tom thornton 2020년 3월 4일
댓글: Robert U 2020년 3월 4일
I am trying to shade this region between the 5 lines I have below(i filled it in using paint), i tried using the fill function but I dont understand how to use it for more than 2 lines.
x=linspace(-1,1);
y=linspace(-10,0);
y2 = 832.4*x-1/(14);
plot(x,y2,'b');
title('Inequalities');
hold on ;
xline(-1/4.2,'r');
yline(0,'k');
hold on ;
y3 = (3443)/(24972)+5.598041235*x;
plot(x,y3,'g');
hold on ;
y4 = 34.43018313*x-(241)/(48928);
plot(x,y4,'m');
hold on;
xlim([-0.3 0]);
ylim([-10 1]);

답변 (1개)

Robert U
Robert U 2020년 3월 4일
Hi tom thornton,
It's a similar question with answer.
Kind regards,
Robert
  댓글 수: 4
tom thornton
tom thornton 2020년 3월 4일
sorry, i dont understand what the booleans would be for me.
Robert U
Robert U 2020년 3월 4일
x=linspace(-1,1);
y=linspace(-10,0);
x1 = -1/4.2;
y1 = 0;
y2 = @(x)832.4*x-1/(14);
y3 = @(x)(3443)/(24972)+5.598041235*x;
y4 = @(x)34.43018313*x-(241)/(48928);
plot(x,y2(x),'b');
title('Inequalities');
hold on ;
xline(x1,'r');
yline(y1,'k');
plot(x,y3(x),'g');
plot(x,y4(x),'m');
xlim([-0.3 0]);
ylim([-10 1]);
v1 = [x1; y4(x1)];
v2 = [x1; min([y3(x1),y1])];
v3 = [-(3443)/(24972)/5.598041235; y1]; % y3 = 0
v4 = [1/(14)/832.4; y1]; % y2 = 0
v5 = [((241)/(48928)-1/(14))/(-832.4+34.43018313);y2(((241)/(48928)-1/(14))/(-832.4+34.43018313))]; % y4 = y2
patch('XData',[v1(1,:),v2(1,:),v3(1,:),v4(1,:),v5(1,:),v1(1,:)],'YData',[v1(2,:),v2(2,:),v3(2,:),v4(2,:),v5(2,:),v1(2,:)],'FaceAlpha',0.7,'FaceColor','red')

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

카테고리

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