Problem when wrapping longitude dataset

12 Ansichten (letzte 30 Tage)
Melissa
Melissa am 13 Mai 2015
Kommentiert: Chad Greene am 14 Mai 2015
Hello,
I have a global dataset that I would like to wrap. I want to change its longitude from [0 360] to [-180 180]. I can successfully wrapTo180 the longitude vector, but when I plot my data, there are lines sporadically across the map. There must be something wrong with the data that is making it do this.
Please help!!
I have attached my data so you can give it a whirl
Thanks,
Melissa
  1 Kommentar
Walter Roberson
Walter Roberson am 13 Mai 2015
Duplicates http://uk.mathworks.com/matlabcentral/answers/216098-problems-with-wrapto180-map but I have let this one stand because it has the data attached and the other one does not.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Chad Greene
Chad Greene am 13 Mai 2015
Does this work?
load lat
load lon
load data
[lon,lat] = meshgrid(wrapTo180(lon_model),lat_model);
worldmap('world')
pcolorm(lat,lon,double(first_model'))
And formatting with the help of rgb, borders, and brewermap,
setm(gca,'ffacecolor',rgb('ocean blue'))
borders('countries','k')
colormap(brewermap(1024,'OrRd'))
  6 Kommentare
Chad Greene
Chad Greene am 14 Mai 2015
I'm not sure why you want to keep that vertical line--it's an artifact of pcolor, which deletes a row and column of data. Before shifting fm with fm = fm(:,[145:end 1:144]);, pcolor would ignore the right-hand column of data, which was the column of data corresponding to the prime meridian. After the shift, pcolor discards the right-hand column of data east of New Zealand. If you want to arbitrarily discard a vertical line of data at the prime meridian, you can do so by
fm(:,144)=NaN;
which gives
Chad Greene
Chad Greene am 14 Mai 2015
Or if you don't want to get rid of any data, you can use imagesc instead of pcolor:
load lat
load lon
load data
fm = double(first_model');
fm = fm(:,[145:end 1:144]);
% Linear arrays of lat and lon:
lon = wrapTo180(lon_model);
lon = linspace(min(lon),max(lon),length(lon));
lat = linspace(-90,90,192);
% gridded lat/lon:
[long,latg] = meshgrid(lon,lat);
% landmask takes ~30 seconds:
land = landmask(latg,long);
% Set land NaNs to zero:
fm(land & isnan(fm)) = 0;
% Set ocean to -1:
fm(isnan(fm))=-1;
imagesc(lon,lat,fm);
axis xy
set(gca,'color',rgb('ocean blue'))
borders('countries','k','nomap')
bm = brewermap(1024,'OrRd');
colormap([rgb('ocean blue');bm])
axis([-180 180 -60 86])

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by