阴影和计算特定区域

阴影和计算特定区域

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

问题描述

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

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:

并且不要忘记推迟...

要计算区域:A = trapz(x(lineStart:lineEnd),y(lineStart:lineEnd))

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

09-06 06:12