griddata_mesh_to_grid

PURPOSE ^

GRIDDATA_MESH_TO_GRID - interpolates data from a mesh to a grid

SYNOPSIS ^

function grid_data=griddata_mesh_to_grid(x_m,y_m,grid_data,x,y,mesh_data,varargin)

DESCRIPTION ^

GRIDDATA_MESH_TO_GRID - interpolates data from a mesh to a grid

   This routine takes a mesh (x,y) and values for every grid of the mesh (mesh_data),
   and interpolates it (using nearest interpolation) onto the gridded data (grid_data). 
   x_m and y_m (vectors of coordinates) are used to find interpolation locations onto grids.

   Usage:
      grid_data=griddata_mesh_to_grid(x_m,y_m,grid_data,x,y,mesh_data,varargin)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function grid_data=griddata_mesh_to_grid(x_m,y_m,grid_data,x,y,mesh_data,varargin)
0002 %GRIDDATA_MESH_TO_GRID - interpolates data from a mesh to a grid
0003 %
0004 %   This routine takes a mesh (x,y) and values for every grid of the mesh (mesh_data),
0005 %   and interpolates it (using nearest interpolation) onto the gridded data (grid_data).
0006 %   x_m and y_m (vectors of coordinates) are used to find interpolation locations onto grids.
0007 %
0008 %   Usage:
0009 %      grid_data=griddata_mesh_to_grid(x_m,y_m,grid_data,x,y,mesh_data,varargin)
0010 
0011 if nargin==7,
0012     roundup=varargin{1};
0013 else
0014     roundup=0;
0015 end
0016 
0017 s=size(grid_data);
0018 if length(x_m) ~= (s(2)+1),
0019     error('x_m should be wider than grid_data by 1');
0020 end
0021 
0022 if length(y_m) ~= (s(1)+1),
0023     error('y_m should be larger than grid_data by 1');
0024 end
0025 
0026 x_m0=x_m(1:end-1);
0027 x_m1=x_m(2:end);
0028 y_m0=y_m(1:end-1);
0029 y_m1=y_m(2:end);
0030 
0031 for i=1:length(x),
0032     if mod(i,100000)==0,
0033         disp(['   progress ' num2str(i/length(x)*100) '%']);
0034     end
0035     posx=find( (x(i)-x_m1)<=0 & (x(i)-x_m0)>0 );
0036     posy=find( (y(i)-y_m1)<=0 & (y(i)-y_m0)>0 );
0037     
0038     y0=posy-roundup;
0039     y1=posy+roundup;
0040     if y0<=0, y0=1; end
0041     if y1>s(1), y1=s(1);end
0042 
0043     x0=posx-roundup;
0044     x1=posx+roundup;
0045     if x0<=0, x0=1; end
0046     if x1>s(2), x1=s(2);end
0047 
0048     grid_data(y0:y1,x0:x1)=mesh_data(i);
0049 end

Generated on Sun 29-Mar-2009 20:22:55 by m2html © 2003