-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetcoordinates.m
55 lines (51 loc) · 1.21 KB
/
getcoordinates.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
function [x,y] = getcoordinates(DEM,type)
%GETCOORDINATES get coordinate vectors of an instance of GRIDobj
%
% Syntax
%
% [x,y] = getcoordinates(DEM)
% [x,y] = getcoordinates(DEM,type)
%
% Input arguments
%
% DEM grid (class: GRIDobj)
%
% Output arguments
%
% x coordinate vector in x direction (row vector)
% y coordinate vector in y direction (column vector)
% type 'vector' (default). Alternatively, you can return coordinate
% matrices ('matrix') or GRIDobjs ('GRIDobj')
% Example
%
% DEM = GRIDobj('srtm_bigtujunga30m_utm11.tif');
% [x,y] = getcoordinates(DEM);
% surf(x,y,double(DEM.Z))
% axis image; shading interp; camlight
%
%
%
% See also: GRIDobj2mat
%
% Author: Wolfgang Schwanghart (w.schwanghart[at]geo.uni-potsdam.de)
% Date: 17. September, 2018
[x,y] = refmat2XY(DEM.refmat,DEM.size);
if nargin == 1
return;
else
type = validatestring(type,{'vector','matrix','GRIDobj'});
end
switch type
case 'vector'
return
case 'matrix'
[x,y] = meshgrid(x,y);
case 'GRIDobj'
[x,y] = meshgrid(x,y);
X = GRIDobj(DEM);
X.Z = x;
Y = GRIDobj(DEM);
Y.Z = y;
x = X;
y = Y;
end