如何在 Matlab 绘图中遮蔽水平线和曲线之间的区域

How to shade area between horizontal line and curve in Matlab plot

我正在尝试为恒定水平线上方的区域添加阴影。水平线上方代表前 10% 的数据(即,我的 90% 数据在水平线下方)。我使用函数 (curve intersect) 找到水平线与我的数据相交的起点和终点。但是,我无法弄清楚如何绘制受曲线约束的水平线上方的区域。有谁知道如何在 Matlab 中做到这一点?附图中提供了我尝试的示例。谢谢!

图1: 黑线是我的水平常量线。红色圆圈代表 'curveintersect' 起点和终点。我试图绘制数据以填充红线,但它捕获的数据低于 10% 线。

图2.我也尝试过使用填充函数,但我再次捕获了蓝色曲线之外的数据。

与图 2 相关的示例代码取自此处 (http://blogs.mathworks.com/graphics/2015/10/13/fill-between/):

mask = y2 > y1; %find where blue curve is greater than the horizontal 90th % line 
fx = [x(mask), fliplr(x(mask))];
fy = [y1(mask), fliplr(y2(mask))];
hold on
fill_color = [.929 .694 .125];
fh = fill(fx,fy,fill_color);
hold off

我已经为 3 个子图重复了 area 函数,每个子图都有相同的代码,只是变量不同:

area(x, max(y, min(x)), min(x), 'EdgeColor','none','FaceColor', [.7 .7 .7]); alpha(.3);

第一个子图(橙色点画线)没有绘制,但第二个和第三个子图是。

使用area如下:

x = 0:.01:4*pi;  %// x data
y = sin(x);      %// y data
level = 0.5;     %// level
plot(x, y)
hold on
area(x, max(y, level), level, 'EdgeColor', 'none', 'FaceColor', [.7 .7 .7])