I want to colour the area between red line and black line below the intersection point. how am i going to do it?

1 次查看(过去 30 天)
I want to colour the area between red line and black line below the intersection point. how am i going to do it?
c=[3,5];
A=[1,2;1,1;0,1];
b=[2000;1500;600];
y1=0:1:max(b);
x21=(b(1)-A(1,1)*y1)./A(1,2);
x22=(b(2)-A(2,1)*y1)./A(2,2);
x23=(b(3)-A(3,1)*y1)./A(3,2);
plot(y1,x21,'r',y1,x22,'k',y1,x23,'b');

回答(2 个)

Chunru
Chunru 2021-11-28
c=[3,5];
A=[1,2;1,1;0,1];
b=[2000;1500;600];
y1=0:1:max(b);
x21=(b(1)-A(1,1)*y1)./A(1,2);
x22=(b(2)-A(2,1)*y1)./A(2,2);
x23=(b(3)-A(3,1)*y1)./A(3,2);
plot(y1,x21,'r',y1,x22,'k',y1,x23,'b');
hold on
fill( [y1(end:-1:993)'; y1(993:end)'; ], [x22(end:-1:993)'; x21(993:end)'], 'y' )

Star Strider
Star Strider 2021-11-28
Use ‘logical indexing’ to identify & fill the appropriate area —
c=[3,5];
A=[1,2;1,1;0,1];
b=[2000;1500;600];
y1=0:1:max(b);
x21=(b(1)-A(1,1)*y1)./A(1,2);
x22=(b(2)-A(2,1)*y1)./A(2,2);
x23=(b(3)-A(3,1)*y1)./A(3,2);
figure
plot(y1,x21,'r',y1,x22,'k',y1,x23,'b');
hold on
Lv = x21 >= x22; % Logical Index To Selecet Vector Segments
patch([y1(Lv) flip(y1(Lv))], [x21(Lv) flip(x22(Lv))], 'g') % Use 'Lv' With 'patch' To Fill The Required Region
hold off
This approach can easily be used to fill other areas of the plot, as required. This requires one indexing line to create ‘Lv’ and one patch call.
.

类别

Help CenterFile Exchange 中查找有关 Problem-Based Optimization Setup 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by