Filter löschen
Filter löschen

How do I calculate area enclosed by contour lines?

100 Ansichten (letzte 30 Tage)
Kushagra Saxena
Kushagra Saxena am 3 Jun. 2014
Kommentiert: S Ch am 2 Aug. 2021
I have
[x, y, z] = peaks; [C, h] = contour(x, y, z, 20);
Kindly suggest an algorithm or necessary functions to find the area enclosed by, and between, contour lines.
Thanks!

Akzeptierte Antwort

Sara
Sara am 3 Jun. 2014
[x, y, z] = peaks;
[C, h] = contour(x, y, z, 20);
ch = get(h,'children');
area = zeros(numel(ch),1);
for i = 1:numel(ch)
x = get(ch(i),'xdata');
y = get(ch(i),'ydata');
[x,y] = poly2cw(x,y);
area(i) = polyarea(x,y);
end
  3 Kommentare
Sara
Sara am 3 Jun. 2014
It's in the mapping toolbox. It orders the points in a contour in clockwise order, so that the contour is external and an area can be computed (counterclockwise contours are considered internal contours). This is ArcGIS convention and it's followed also by Matlab (not sure who started first). I personally don't have a version working with the basic matlab license and never looked if there is something similar in the file exchange since I have the mapping toolbox.
XING ZHENG
XING ZHENG am 7 Nov. 2017
Dear Sara,
Now I am using your function in the version 2017b: [C, h] = contour(x, y, z, 20); ch = get(h,'children');
However, I can not get 'h' from this sentence. therefore, there is No result of ch. I think this is the difference between the version 2014b and 2017b.
How can I fix this problem? Thanks
Xing

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

A. Shokouhi
A. Shokouhi am 19 Sep. 2018
I believe some commands in the code provided by Sara is not available in new versions here a code I wrote down that does the same job.
[x, y, z] = peaks;
[C, h] = contour(x, y, z, 5);
n = 0;
i = 1;
sz = size(h.ContourMatrix,2);
nn(1) = h.ContourMatrix(2,1);
xx = h.ContourMatrix(1,2:nn(1)+1);
yy = h.ContourMatrix(2,2:nn(1)+1);
area(1) = polyarea(xx,yy);
while n+nn(i)+i < sz
n = n + nn(i);
i = i + 1;
nn(i)=h.ContourMatrix(2,n+i);
xx = h.ContourMatrix(1,n+i+1:n+nn(i)+i);
yy = h.ContourMatrix(2,n+i+1:n+nn(i)+i);
area(i) = polyarea(xx,yy);
end
  4 Kommentare
Sesha Sai Anudeep Karnam
Sesha Sai Anudeep Karnam am 20 Mär. 2020
Is this area enclosed by contour lines or area enclosed between contour lines?
S Ch
S Ch am 2 Aug. 2021
@Sesha Sai Anudeep Karnam Hello, did you have an answer ? I think it gives the area of the colors,
Is it the integral ?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Contour Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by