MATLAB: Contourm plotting

contourcontourmMapping Toolbox

I have 3 vectors of data each 655432×1 (so essentially a list of values) X (latitude) Y (Longitude) and Z (Ozone). I am trying to do a simple contour plot whereby I can map these XYZ to create a plot showing a location (X and Y) with each coordinate relating to a value (Z).
My data exists in separate vector files in my work space (latitude, longitude and ozone). Maybe it should be noted that ozone values are between -99.999 (which essentially means that data could not be obtained) and 871.
I tried to use the contourm function and received this notice;
>> worldmap
>> contourm(latitude, longitude, ozone)
??? Error using ==> parseContourInputs>checkLatLonZ at 93
Length of LON must match number of columns in Z.
Error in ==> parseContourInputs at 57
[lat, lon] = checkLatLonZ(lat, lon, Z, function_name);
Error in ==> calcContour at 49
inputs = parseContourInputs(function_name, varargin{:});
Error in ==> contourm at 118
varargout = calcContour(mfilename, @contour, nargout, varargin{:});
I have been trying this for a while now and am getting nowhere. Let me know if I can give you any more details.

Best Answer

According to the documentation for contourm, vector inputs are allowed only if the lengths of lat and lon correspond to the number of rows and columns of Z, respectively. Alternatively, lat, lon, and Z must be matrices that represent a grid. So you can transform your vector data to a grid. Here's an example of how you can do that using griddata:
% Create a grid of latitude and longitude
[LatGrid, LonGrid] = meshgrid(linspace(min(latitude), max(latitude)), ...
linspace(min(longitude), max(longitude)));
% Use griddata to compute ozone for each grid point
OzoneGrid = griddata(latitude, longitude, ozone, LatGrid, LonGrid);
% Call contourm
contourm(LatGrid, LonGrid, OzoneGrid);
If you're using R2009a or newer, use TriScatteredInterp class for efficiency.