MATLAB: Making an equidistant latlon grid from a non equidistant latlon grid

gridgriddatalatlonmeshgrid

I have the following type of ascii dataset: A 3 vector array with gridded latlon data with size [3,62880] in which the first column represents longitude values, the second column latitude values and the third height values. This consists of a full latlon grid made onedimensional. The latitude and longitude gridsizes are 240 and 262 respectively. (So this data can be easily put into a grid for plotting purposes). But (coming from a UTM conversion) the lat and lon values are not equidistant (and unevenly spaced) and I want to get an equidistant grid. So far I have tried to it like this:
x = data(1,:); %longitude
y = data(2,:); %latitude
z = data(3,:); %height
xmin = min(x); ymin = min(y);
xmax = max(x); ymax = max(y);
nlat = 240;
mlon = 262;
xv = linspace(xmin, xmax, mlon);
yv = linspace(ymin, ymax, nlat);
[X,Y] = meshgrid(xv,yv);
[X,Y,Z] = griddata(x,y,z,X,Y);
ID = isnan(Z);
Z(ID) = -9999;
Is this the correct way to do it? I obtain quite a bunch of missing values (which I set to -9999 for further processing) with trying different interpolation (should I use something else than griddata and meshgrid?) methods, and I want to minimize that as much as possible. Besides, I feel like some of the data is lost with this method. Could somebody recommend me the best way to convert a non equidistant latlon grid to a equidistant grid with correctly interpolated height values?
I hope I have provided enough information for you to help me, if not, ask me to provide more. I feel I might be doing something wrong with the conversion from the 1D vectors to the 2D grid as well (but find it hard to write down how it is originally put into the current array) but I doubt it has something to with the missing values.
Thanks in advance!
(for people known with NCL this is the way I usually read this data (which might explain the format)):
lon2d = onedetond(x,(/nlat,mlon/)) lat2d = onedtond(y, (/nlat,mlon/)) z2d = onedtond(z,(/nlat,mlon/))

Best Answer

Look at the matlab function: griddata, (there is nowadays a similar function with a new name that eludes me at the moment.) or John D'Errico's gridfit function: http://www.mathworks.se/matlabcentral/fileexchange/8998-surface-fitting-using-gridfit, that provides some smoothing as well, while griddata does a triangulation-interpolation.
HTH,