フィルターのクリア

Coloring area between two graphs in specific interval

22 ビュー (過去 30 日間)
Christopher
Christopher 2024 年 7 月 6 日 11:00
コメント済み: Star Strider 2024 年 7 月 6 日 18:51
Hi,
I have a plot that looks as shown and would like to color specific areas of it. In the blue graph, I would like shade the area of the minimum, so roughly between 100 < x < 115 and up to y = 0.45 (the area below the baseline).
I had no success doing this using a linear function and the inBetween and fill functions.
Thanks a lot,
Chris

採用された回答

Star Strider
Star Strider 2024 年 7 月 6 日 14:01
It would help to have the code, or at least a file thtat I can get the information from.
Lacking that, a bit of creativity is in order —
x = linspace(-50, 175, 500).'; % Assume Column Vectors
y = -0.45 - 2*exp(-(x-107.5).^2/4)+(-0.0005*x);
Lv = (x > 100) & (x < 115);
Lvn = find(Lv);
ytop = interp1(x([Lvn(1) Lvn(end)]), y([Lvn(1) Lvn(end)]), x(Lvn));
figure
plot(x, y)
hold on
patch([x(Lv); flip(x(Lv))], [y(Lv); ytop], 'b', 'FaceAlpha',0.5, 'EdgeColor','none')
hold off
grid
xlim([min(x) max(x)])
It is a bit difficult to understand what you want shaded. This is my best guess.
.
  2 件のコメント
Christopher
Christopher 2024 年 7 月 6 日 18:18
編集済み: Christopher 2024 年 7 月 6 日 18:18
Your guess was correct and your code works perfectly. Thank you!
Star Strider
Star Strider 2024 年 7 月 6 日 18:51
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by