Shade an area between 5 lines

3 次查看(过去 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 中查找有关 Graphics Object Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by