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

3 次查看(过去 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