阴影并计算特定面积 [英] Shade and calculate specific area

查看:136
本文介绍了阴影并计算特定面积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以某种方式更改代码,以便仅第一个区域显示为灰色.如何设置水平线,使其仅出现在我要阴影的区域下方?

I tried to change the code in a way so that only the first area is shaded grey. How can I set the horizontal line in a way that it only appears under the area I want to shade?

此外,我想计算一个区域的面积.我该如何实现?我知道它是trapz,但是我不确定如何设置边界.谢谢!

Furthermore I want to calculate the area of ONE region. How do I achieve that? I know it is trapz but I am not sure how to set the boundaries. Thanks!

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])

曲线:-

推荐答案

您也可以尝试以下简单选项:

you can try also this simple option:

x = 0:.01:4*pi;  %// x data
y = sin(x);      %// y data
level = 0.5;     %// level
lineStart = find(y>=level,1);
lineEnd = find(y(lineStart:end)<=level,1)+lineStart;
plot(x,y)
hold all
area(x(lineStart:lineEnd),y(lineStart:lineEnd),...
     level,'EdgeColor', 'none', 'FaceColor', [.7 .7 .7],'ShowBaseLine','off')
line([x(lineStart),x(lineEnd)],[level level ])
hold off

未事先定义感兴趣的领域:

without defining areas of interest a-priory:

别忘了hold off ...

要计算面积: A = trapz(x(lineStart:lineEnd),y(lineStart:lineEnd))

这篇关于阴影并计算特定面积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆