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');
댓글 수: 0
답변 (2개)
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' )
댓글 수: 0
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.
.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!