% Grid and contour Illinois magnetics data
RandGridDataIllinoisMagnetics % obtain 200 random x-y
% locations and magnetics (z) values
dx = 6/19; % grid interval
[X,Y] = meshgrid(0:dx:6); % define x-y grid locations
Z = griddata(x,y,z,X,Y,'cubic');
% use nearest neighbor option to get gridded values on edges
% lower edge
x1 = [0:dx:6];
y1 = zeros(1,20);
z1 = griddata(x,y,z,x1,y1,'nearest');
Z(1,:) = z1;
% upper edge
x1 = [0:dx:6];
y1 = ones(1,20)*6;
z1 = griddata(x,y,z,x1,y1,'nearest');
Z(20,:) = z1;
% left edge
y1 = [dx:dx:6-dx];
x1 = zeros(1,18);
z1 = griddata(x,y,z,x1,y1,'nearest');
for i=2:19
Z(i,1) = z1(i-1);
end
% right edge
y1 = [dx:dx:6-dx];
x1 = ones(1,18)*6;
z1 = griddata(x,y,z,x1,y1,'nearest');
for i=2:19
Z(i,20) = z1(i-1);
end
% Plot color image and overlay contours
pcolor(X,Y,Z)
shading interp
colorbar
hold on
% Contour the gridded data
v = [-200:100:800];
[c,h] = contour(X,Y,Z,v,'w-');
clabel(c,h,'color','w','fontweight','bold','fontsize',15)
axis square
hold off
pause
% use interp2 to regrid for increased resolution and smoothness
[XI,YI] = meshgrid(0:dx/4:6);
ZI = interp2(X,Y,Z,XI,YI,'cubic');
% replot color display and contour map for interpolated data
pcolor(XI,YI,ZI)
shading interp
colorbar
hold on
% Contour the gridded data
v = [-200:100:800];
[c,h] = contour(XI,YI,ZI,v,'w-');
clabel(c,h,'color','w','fontweight','bold','fontsize',15)
axis square
hold off
pause
surf(XI,YI,ZI);




