File to convert .xyz file (with variable named "data") to .mat file
Created during a January 2011 introductory workshop for Matlab held at the Horn Point Laboratory.
First download a bathymetry/topography file from the GEODAS Grid Translator - Design-a-Grid website here. Then import the .xyz file into matlab and rename the variable "data". Once those steps are completed you can run this file to grid the latitude, longitude, and elevation triplets for contouring and plotting.
Jamie Pierson, January 2011
Note that the x and y vectors that specify the locations for the newly gridded data must be in opposite orientations, thus I use the ' command on the x data to transpose it and make it a horizontal vector.
% The lines below show an iterative process for gridding the data. In % benchmark tests on my desktop (Win XP SP 3, Matlab R2010a), the old % method below took 14.65 seconds, while using "griddata" took only 1.55 % seconds. % % Here we are gridding the unique Lon/Lat pairs % [Lon,Lat]=meshgrid(x,y); % Depth=nan(size(Lon)); % tic % for i=1:length(x) % for j=1:length(y) % % Depth(j,i)=data(data(:,1)==x(i) & data(:,2)==y(j),3); % % end % end % toc % clearing variables we will not be using clear i j