%create_grid % % Usage: % [X Y Z] = create_grid(xPts, yPts, zPts, xSpacing, ySpacing, method, % useNumBlocks) % % This function adds a contour plot of the provided data to the current % figure, and plots the data point locations on top of the contour plot. % Note that the title, axis labels, etc. must be handled outside of the % function. % % Input arguments: % xPts, yPts, zPts: Arrays of the x-, y-, and z-locations of the data % points. % xSpacing, ySpacing: Desired grid spacing for the plot. Exact meaning depends on % the value of useNumBlocks. % method: String containing the interpolation method. Allowed values are % 'linear', 'cubic', 'nearest', and 'v4'. See help for griddata % for more information. % useNumBlocks: Flag to determine how xSpacing and ySpacing are used. % Values: % 0: Treat xSpacing, ySpacing as the distance between % each grid point. % non-0: Select xSpacing evenly-spaced grid points in the % x-direction, and ySpacing evenly-spaced points % in the y-direction. % % Outputs: % X, Y, Z: 2D matrices containing X- Y- and Z-positions of the gridded data % points, respectively. % % Author: Robert Wagner % Date: 2nd March 2009 % Last Modified: 12th March 2009 function [X Y Z] = create_grid(xPts, yPts, zPts, xSpacing, ySpacing, method, useNumBlocks) if useNumBlocks == 0 % Interpret *Spacing as the size of each step xSpace = min(xPts):xSpacing:(max(xPts)+xSpacing); ySpace = min(yPts):ySpacing:(max(yPts)+ySpacing); else % Interpret *Spacing as the number of steps xStep = (min(xPts)-max(xPts))/xSpacing; xStep = abs(xStep); xSpace = [min(xPts):xStep:max(xPts)]; yStep = (min(yPts)-max(yPts))/ySpacing; yStep = abs(yStep); ySpace = [min(yPts):yStep:max(yPts)]; end % ySpace' means to rotate ySpace, as it needs to be a column vector. [X Y Z] = griddata(xPts,yPts,zPts,xSpace,ySpace',method);