Problem when wrapping longitude dataset

12 ビュー (過去 30 日間)
Melissa
Melissa 2015 年 5 月 13 日
コメント済み: Chad Greene 2015 年 5 月 14 日
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 件のコメント
Walter Roberson
Walter Roberson 2015 年 5 月 13 日
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.

サインインしてコメントする。

採用された回答

Chad Greene
Chad Greene 2015 年 5 月 13 日
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 件のコメント
Chad Greene
Chad Greene 2015 年 5 月 14 日
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 2015 年 5 月 14 日
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])

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by