How can I make MATLAB shade the area of the virtual intersection between two lines?

조회 수: 4 (최근 30일)
The below code will plot a figure of two lines (red and blue) and few dashed lines to help you visualize what I am talking about. Is there a way I can make MATLAB shade the region that is occupied by both lines? If you don't know what I mean, its the rectangular region bounded by the dashed lines made from the two lines.
x1 = ones(1,10);
y1 = ones(1,1000000);
n1 = 10^10:10000000000:10^16;
T1 = 10:1:19;
loglog(n1, y1, 'LineWidth', 2)
hold on
loglog(x1, T1, 'LineWidth', 2)
%%Shaded Lines code
d = 1:10^15:10^16;
e = 1:1:100;
d1 = [10, 10, 10, 10, 10, 10, 10 , 10, 10, 10, 10];
d2 = [19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19];
d3 = zeros(1,100)+10^10;
d4 = zeros(1,100)+10^16;
loglog(d, d1, 'k--')
loglog(d, d2, 'k--')
loglog(d3, e, 'k--')
loglog(d4, e, 'k--')

채택된 답변

Star Strider
Star Strider 2021년 9월 12일
Both fill and patch require a closed region —
x1 = ones(1,10);
y1 = ones(1,1000000);
n1 = 10^10:10000000000:10^16;
T1 = 10:1:19;
figure
loglog(n1, y1, 'LineWidth', 2)
hold on
loglog(x1, T1, 'LineWidth', 2)
%%Shaded Lines code
d = 1:10^15:10^16;
e = 1:1:100;
d1 = [10, 10, 10, 10, 10, 10, 10 , 10, 10, 10, 10];
d2 = [19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19];
d3 = zeros(1,100)+10^10;
d4 = zeros(1,100)+10^16;
loglog(d, d1, 'k--')
loglog(d, d2, 'k--')
loglog(d3, e, 'k--')
loglog(d4, e, 'k--')
patch([d3(1) d4(1) d4(1) d3(1)], [d1(1) d1(1) d2(1) d2(1)], 'g', 'FaceAlpha',0.5)
This instance is relatively straightforward.
.

추가 답변 (1개)

Matt J
Matt J 2021년 9월 11일
You can use fill() or patch().

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by