Filling area between lines with color

5 ビュー (過去 30 日間)
Sebastian Daneli
Sebastian Daneli 2021 年 8 月 18 日
編集済み: Yazan 2021 年 8 月 18 日
I have this figure:
And I wish to fill the area between the two straight lines with a color. I've looked around and tried fill and patch, but they don't seem to work with my straight lines? The straight lines are created by:
Line1=0.1*ones(length(signal),1);
Line2=-Line1;
Any ideas what the problem is and how to solve it?
  3 件のコメント
Sebastian Daneli
Sebastian Daneli 2021 年 8 月 18 日
@Yazan, already have. Does not work with my lines.
Yazan
Yazan 2021 年 8 月 18 日
編集済み: Yazan 2021 年 8 月 18 日
clc, clear
x = 1:100;
y1 = 0.1*ones(size(x));
y2 = -y1;
plot(x, y1), hold on, plot(x, y2)
xx = [x fliplr(x)];
yy = [y1, fliplr(y2)];
fill(xx, yy, 'g', 'FaceAlpha', 0.1, 'EdgeColor', 'none')
ylim([-1, 1])
That's exactly the answer here. Why it doesn't work?

サインインしてコメントする。

採用された回答

Wan Ji
Wan Ji 2021 年 8 月 18 日
編集済み: Wan Ji 2021 年 8 月 18 日
If your horizontal coordinates is t array, then patch or fill can help
maxTime = max(t(:));
patch([0, maxTime, maxTime, 0], [-0.1, -0.1, 0.1, 0.1], 'r', 'facealpha', 0.3, 'edgecolor','none')
Or fill command
maxTime = max(t(:));
fill([0, maxTime, maxTime, 0], [-0.1, -0.1, 0.1, 0.1], 'r', 'facealpha', 0.3, 'edgecolor','none')
  1 件のコメント
Sebastian Daneli
Sebastian Daneli 2021 年 8 月 18 日
Thx, this should work.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by