contourm plotting

11 次查看(过去 30 天)
John Ball
John Ball 2011-1-31
I have 3 vectors of data each 655432x1 (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.

采纳的回答

Jiro Doke
Jiro Doke 2011-1-31
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.
  1 个评论
John Ball
John Ball 2011-1-31
Such a huge help! Thank you very much

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2011-1-31
contourm does allow vectors for lat and lon:
"Geolocation arrays having the same size as Z, or vectors with length (lat) matching the number of rows in Z and length (lon) matching the number of columns in Z."
However the implication is that Z must be a grid, which is not the case for you.
In order to use contourm on your data, you will need to use griddata3() or similar (such as the Matlab File Exchange contribution gridfit) to create a grid of points with Z defined over it. (Note: TriScatteredInterp is recommended instead of griddata3() )
If the situation is such that there is no reasonable interpolating function, you will have an inherent problem in creating contours.
  1 个评论
Jiro Doke
Jiro Doke 2011-1-31
Yes, you're right. lat and lon can be vectors, but only if they are the corresponding grid points for Z. For this case, the three vectors construct X-Y-Z combinations. I'll adjust my answer above.
I think griddata (not griddata3) is sufficient for this case, since he has lat-lon-ozone. TriScatteredInterp is recommended if using R2009a or newer.

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by