-
Notifications
You must be signed in to change notification settings - Fork 110
/
hypscurve.m
executable file
·85 lines (71 loc) · 1.64 KB
/
hypscurve.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
function varargout = hypscurve(DEM,bins)
%HYPSCURVE plot hypsometric curve of a digital elevation model
%
% Syntax
%
% hypscurve(DEM)
% hypscurve(DEM,nrbins)
% ax = hypscurve(...)
% [rf,elev] = hypscurve(...)
%
% Description
%
% A hypsometric curve is an empirical cumulative distribution function
% of elevations in a catchment. hypscurv plots the hypsometric curve or
% returns the relative frequencies of elevation values. Optionally,
% hypscurve bins the data in equally spaced containers.
%
% Input
%
% DEM digital elevation model (GRIDobj)
% nrbins number of bins
%
% Output
%
% ax axis handle
% rf relative frequencies (in %)
% elev elevation
%
% Example
%
% DEM = GRIDobj('srtm_bigtujunga30m_utm11.tif');
% hypscurve(DEM,50)
%
% See also: hist, histogram
%
% Author: Wolfgang Schwanghart (w.schwanghart[at]geo.uni-potsdam.de)
% Date: 8. January, 2013
dem = DEM.Z;
dem = dem(~isnan(dem));
dem = dem(:);
if nargin == 2;
[n,elev] = hist(dem,bins);
n = flipud(n(:));
elev = flipud(elev(:));
n = cumsum(n);
linestyle = 'o-';
else
elev = sort(dem);
elev = flipud(elev(:));
% return unique entries only
I = [true;diff(elev)~=0];
elev = elev(I);
n = find(I);
linestyle = '-';
end
% get relative frequencies
n = n./n(end) * 100;
% plot results
if nargout ~= 2;
axis_handle = plot(n,elev,linestyle);
axis xy
xlabel('frequency [%]')
ylabel('elevation [m]')
end
% prepare output
if nargout == 1
varargout{1} = axis_handle;
elseif nargout == 2;
varargout{1} = n;
varargout{2} = elev;
end