MATLAB Answers

Contour plot of spatial distribution of temperature

28 views (last 30 days)
David Lopez
David Lopez on 15 May 2012
Answered: Chad Greene on 4 Apr 2021
i have 5 block data i only need 3
Lat lon month year temp
22.25000 -98.25, 1, 2000, 0.1061891
22.25000, -97.75, 1, 2000, 0.2013340
22.25000, -97.25, 1, 2000, -999.9000
22.25000, -96.75, 1, 2000, -999.9000
22.75000, -100.75, 1, 2000, 0.4650421
22.75000, -100.25, 1, 2000, 0.3308848
22.75000, -99.75, 1, 2000, 0.2076520
22.75000, -99.25, 1, 2000, 0.1700439
22.75000, -98.75, 1, 2000, 0.1031799
22.75000, -98.25, 1, 2000, 0.1318403
22.75000, -97.75, 1, 2000, 0.3397914
22.75000, -97.25, 1, 2000, -999.9000
22.75000, -96.75, 1, 2000, -999.9000
23.25000, -100.75, 1, 2000, 0.4653015
23.25000, -100.25, 1, 2000, 0.3465271
i have develop a contour plot of spatial distribution of temperature
even some values have -999.999 some way to interpolate these values and replace it in the vector of temp.
i already started with this
archivo=load('escenarioA2.txt');
lat=archivo(:,1);
lon=archivo(:,2);
month=archivo(:,3);
year=archivo(:,4);
inc=archivo(:,5);
[m,n]=size(archivo);
nx = length(lon);
ny = length(lat);
[X,Y]=meshgrid(lon,lat);

Accepted Answer

Geoff
Geoff on 15 May 2012
I would start by removing the invalid readings:
archivo( archivo(:,5) < -999, : ) = [];
You need to have a higher (and uniform) granularity for your grid... How about this:
latmin = min(lat); latmax = max(lat);
lonmin = min(lon); lonmax = max(lon);
glat = linspace( latmin, latmax, ceil((latmax-latmin)/0.01) );
glon = linspace( lonmin, lonmax, ceil((lonmax-lonmin)/0.01) );
[X,Y] = meshgrid(glon, glat);
Now, you want to interpolate your data into that grid. Look at the following function:
doc interp2
  1 Comment
David Lopez
David Lopez on 15 May 2012
and for plot a spatial distribution which command do you recommend me?

Sign in to comment.

More Answers (1)

Chad Greene
Chad Greene on 4 Apr 2021
The regular quarter-degree spacing of the data suggests that no interpolation is necessary for this dataset--it just needs to be restructured. An easy way to do that is with a function of mine called xyz2grid.
For your matrix M whose columns correspond to [lat, lon, month, year, temp], use longitude as the "x" data and latitude as the "y" data, then grid it up like this:
[Lon,Lat,Temp] = xyz2grid(M(:,2),M(:,1),M(:,5));
Then NaN-out the no-data values like this:
Temp(Temp==-999.9) = nan;

Community Treasure Hunt

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

Start Hunting!