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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by