Compute that portion of a surface above a threshold
Show older comments
Hi. I have a variable Z define over a grid of points X,Y. I would like to compute the area of my domain where Z>threshold.
Right now I tried to compute it as
A = trapz(X_vector, trapz(Y_vector, Z> threshold));
This gives acceptable results, however this approach set the border between the "in" and the "out" areas always in the middle of the last point outside and the first point inside.
To better explain the problem, consider the 1-dimensional case where
x = 1:10;
y = ones(1,10);
y(5) = 2;
threshold = 1.99;
plot(x,y)
hold all
plot(xlim,[1 1]*threshold ,'--k')
Analytically, the portion of the curve above the threshold is equal to 0.2 x-units. However if we plot
plot(x,y>threshold)
and we compute
L = trapz(x,y>threshold)
L =
1
This is due to the fact that this approach ignores that y(5) is way closer to the threshold than y(4) and y(6).
On the 2D case You can visualize the "correct" solution using
contour(X,Y,Z,[1 1]*threshold)
The problem is that if the contour line is open the computation of the area becomes tricky.
Any suggestions?
Thank you
Accepted Answer
More Answers (0)
Categories
Find more on Polygonal Shapes in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
