Problem when wrapping longitude dataset
조회 수: 14 (최근 30일)
이전 댓글 표시
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
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
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'))
setm(gca,'ffacecolor',rgb('ocean blue'))
borders('countries','k')
colormap(brewermap(1024,'OrRd'))
댓글 수: 6
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
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!