3.0

3.0 | 1 rating Rate this file 11 Downloads (last 30 days) File Size: 2.03 KB File ID: #26480
image thumbnail

Contour2Area

by Per Sundqvist

 

26 Jan 2010

Gives the area of polygons from the matlab function C=contour(x,y,z) and their centroids.

| Watch this File

File Information
Description

Gives the area of the polygons that are created from the matlab function C=contour(x,y,z,...); It also gives the centroids (centre of mass) of each polygon. The structure of C delivered by contour is a bit complicated to work with itself, why I developed this matlab function.

Syntax: [Area,Centroid,IN]=Contour2Area(C)
Takes the contour argument C from matlabs function contourc
as produced by C=contour(x,y,z,...) and convert the contours
to closed polygons from where the areas are calculated.
In addition the centroids (centre of mass) Cxy are calculated
and a matrix IN determining the parent/child relationship
between the contours (if polygon i is inside j then IN_ij=1, else=0).
For obscure contours NaN would be retrived, but are excluded in output.
%
Created By: Per Sundqvist 2010-01-26, ABB/CRC, Västerås/Sweden.
%
%--- Example ---
[X,Y,Z] = PEAKS(50);
figure(1), clf;
%C=contourf(X,Y,Z,0.37+[0 0]);
C=contourf(X,Y,Z,5);
[Area,Centroid,IN]=Contour2Area(C);
xc=Centroid(1,:);yc=Centroid(2,:);
hold on;plot(xc,yc,'k*');
Area
IN

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
28 Jan 2010 Zhang Yanxiang

How do you deal with non-close contour? e.g.,
>> [X,Y] = meshgrid(-10:10);Z=X.^2;

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
contourc Per Sundqvist 26 Jan 2010 10:29:27
inpolygon Per Sundqvist 26 Jan 2010 10:29:27
polyarea Per Sundqvist 26 Jan 2010 10:29:27
centroid Per Sundqvist 26 Jan 2010 10:29:27
centre of mass Per Sundqvist 26 Jan 2010 10:29:27
contourf Per Sundqvist 26 Jan 2010 10:29:27
area Per Sundqvist 26 Jan 2010 10:29:27
contour Per Sundqvist 26 Jan 2010 10:29:27
polygon Per Sundqvist 26 Jan 2010 10:29:27
centroid Hubert 01 Jul 2010 09:31:23
centroid AJP 28 Dec 2010 04:32:25

Contact us at files@mathworks.com