필터 지우기
필터 지우기

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