-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetMap.m
executable file
·50 lines (46 loc) · 1.29 KB
/
getMap.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
function [ Xz, Yz, Zz ] = getMap( strfile,box )
% GETMAP Gets a binary map as generated by mapbuilder
% [ Xb, Yb, Zb ] = GETMAP( strfile )
% Argument strfile is filename to read from. Zb = f( Xb, Yb ) is returned.
% box = [xmin xmax ymin ymax] all in meters for zoom around cross-point
xmin = box(1);
xmax = box(2);
ymin = box(3);
ymax = box(4);
xmin = round(xmin/200);
xmax = round(xmax/200);
xmin = 1001+xmin;
xmax = 1001+xmax;
ymin = round(ymin/200);
ymax = round(ymax/200);
ymin = 1001+ymin;
ymax = 1001+ymax;
fid = fopen( strfile, 'rb' );
if fid<0
disp(sprintf('Error! Could not open map file %s!',strfile))
return
end
nx = fread( fid, 1, 'int16' );
ny = fread( fid, 1, 'int16' );
dx = fread( fid, 1, 'float32' );
dy = fread( fid, 1, 'float32' );
x0 = fread( fid, 1, 'float32' );
y0 = fread( fid, 1, 'float32' );
Zb = zeros( ny, nx );
for ky = 1:ny
Zb( ky, : ) = fread( fid, nx, 'int16' )';
end
fclose( fid );
Xb = x0 + dx*[ 0:(nx-1) ];
Yb = y0 + dy*[ 0:(ny-1) ];
%contourf(Xb,Yb,Zb)
% if ymax<0 | xmax<0
% Xz = 0;
% Yz = 0;
% Zz = 0;
% return;
% end
Xz = Xb(xmin:xmax);
Yz = Yb(ymin:ymax);
Zz = Zb(ymin:ymax,xmin:xmax);
%contourf(Xz,Yz,Zz,20)