-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathC2xyz.m
86 lines (80 loc) · 2.43 KB
/
C2xyz.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function [x,y,z] = C2xyz(C)
% C2XYZ returns the x and y coordinates of contours in a contour
% matrix and their corresponding z values. C is the contour matrix given by
% the contour function.
%
%% Citing Antarctic Mapping Tools
% This function was developed for Antarctic Mapping Tools for Matlab (AMT). If AMT is useful for you,
% please cite our paper:
%
% Greene, C. A., Gwyther, D. E., & Blankenship, D. D. Antarctic Mapping Tools for Matlab.
% Computers & Geosciences. 104 (2017) pp.151-157.
% http://dx.doi.org/10.1016/j.cageo.2016.08.003
%
% @article{amt,
% title={{Antarctic Mapping Tools for \textsc{Matlab}}},
% author={Greene, Chad A and Gwyther, David E and Blankenship, Donald D},
% journal={Computers \& Geosciences},
% year={2017},
% volume={104},
% pages={151--157},
% publisher={Elsevier},
% doi={10.1016/j.cageo.2016.08.003},
% url={http://www.sciencedirect.com/science/article/pii/S0098300416302163}
% }
%
%% Syntax
%
% [x,y] = C2xyz(C)
% [x,y,z] = C2xyz(C)
%
%% Description
%
% [x,y] = C2xyz(C) returns x and y coordinates of contours in a contour
% matrix C
%
% [x,y,z] = C2xyz(C) also returns corresponding z values.
%
%
%% Example
% Given a contour plot, you want to know the (x,y) coordinates of the contours,
% as well as the z value corresponding to each contour line.
%
% C = contour(peaks);
% [x,y,z] = C2xyz(C);
%
% This returns 1 x numberOfContourLines cells of x values and y values, and
% their corresponding z values are given in a 1 x numberOfContourLines
% array. If you'd like to plot a heavy black line along all of the z=0
% contours and a dotted red line along the z = -2 contours, try this:
%
% hold on; % Allows plotting atop the preexisting peaks plot.
% for n = find(z==0); % only loop through the z = 0 values.
% plot(x{n},y{n},'k','linewidth',2)
% end
%
% for n = find(z==-2) % now loop through the z = -2 values.
% plot(x{n},y{n},'r:','linewidth',2)
% end
%
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
% Created by Chad Greene, August 2013.
%
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
% See also contour, contourf, clabel, contour3, and C2xy.
m(1)=1;
n=1;
try
while n<length(C)
n=n+1;
m(n) = m(n-1)+C(2,m(n-1))+1;
end
end
for nn = 1:n-2
x{nn} = C(1,m(nn)+1:m(nn+1)-1);
y{nn} = C(2,m(nn)+1:m(nn+1)-1);
if nargout==3
z(nn) = C(1,m(nn));
end
end
end