C2xyz contour matrix to coordinates
by
Chad Greene
21 Aug 2013
(Updated
22 Aug 2013)
Convert values given by a contour matrix to easytouse cells.

C2xy(C) 
function [x,y] = C2xy(C)
% [x,y] = C2xy(C) returns the x and y coordinates of contours in a contour
% matrix. C is the contour matrix given by the contour function.
%
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
% EXAMPLE: You have some data and you're interested in the z = 3 isopleth.
% But where in (x,y) coordinates does z equal 3?
%
% C = contour(peaks,[3 3]);
% [x,y] = C2xy(C);
%
% That's where z equals 3, at [x,y]. You'll notice you now have x and y
% cells in your workspace, each sized 1 x numberOfContourLines. One of the
% contours has the xcoordinates given by x{1}, and the ycoordinates given
% by y{1}. Another contour has the x and ycoordinates given by x{2} and
% y{2}. Plot them all by:
%
% figure; hold on;
% for n = 1:length(x)
% plot(x{n},y{n})
% end
%
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
% Created by Chad Greene, August 2013.
%
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
% See also contour, contourf, clabel, contour3, and C2xyz.
m(1)=1;
n=1;
try
while n<length(C)
n=n+1;
m(n) = m(n1)+C(2,m(n1))+1;
end
end
for nn = 1:n2
x{nn} = C(1,m(nn)+1:m(nn+1)1);
y{nn} = C(2,m(nn)+1:m(nn+1)1);
end
end


Contact us