a = isfinite(Zsave);

%find columns with any real finite numbers
c = any(a,2);
%find first column with a finite number
cFirst = min(find(c==1));
%find last column with a finite number
cLast = max(find(c==1)); 

%find rows with any real finite numbers
r = any(a,1);
%find first row with a finite number
rFirst = min(find(r==1));
%find last column with a finite number
rLast = max(find(r==1)); 

Z2 = Zsave(cFirst:cLast, rFirst:rLast);

fprintf(1, 'Getting Haxby color map ...\n');
cm = haxby(256);

fprintf(1, 'Showing map ...\n');
figure
mapshow(Z2,R,'DisplayType','surface');
xlabel('x (easting in meters)'); 
ylabel('y (northing in meters)')
colormap(cm);

% View the terrain in 3-D
fprintf(1, 'Formating the map ...\n');
axis normal; 
view(2); 
axis equal; 
grid on
zlabel('elevation in meters')