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

4 visualizaciones (últimos 30 días)
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--')

Respuesta aceptada

Star Strider
Star Strider el 12 de Sept. de 2021
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.
.

Más respuestas (1)

Matt J
Matt J el 11 de Sept. de 2021
You can use fill() or patch().

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by