# Trying to shift/recenter map and data

조회 수: 4(최근 30일)
Brian DeCicco 2021년 7월 27일
댓글: Brian DeCicco 2021년 7월 28일
Hello, I have a 3-D dataset of sea surface temperatures. My matrix is of size 1440x721x1, where the first dimension is longitude, the second is lattitude, and the 3rd dimension is the averged sea surface temperatures at 1 time. My longtitude values run from 0 to 360 degrees, but I would like to recenter the data on the prime meridian (0 degrees). Ideally, I'd like to convert my 0 to 360 grid into a grid spanning from -180 to 180 and center the map and data on 180 degrees instead of 0. I've tried just about everything under the sun and end up with a result of either my data shifting and the map doesn't, or the map shifts and the data doesnt. Does anyone have any simple solutions to this?
figure(1)
pcolor(long,lat,array_1(:,:,1)');
colorbar;xlabel('Longitude');ylabel('Latitude');
% axis([275 350 25 60]);
set(gca,'clim',[275 300]);

댓글을 달려면 로그인하십시오.

### 채택된 답변

Adam Danz 2021년 7월 27일
편집: Adam Danz 2021년 7월 28일
You can wrap your longitudinal values to [-180,180] using wrapTo180() which requires the mapping toolbox.
Or you could use wrapToInterval() from the file exchange: wrapToInterval(long,[-180,180]);
Edit:
You'll also need the wrapped X data to be in the same order as the original X data and then resort the color value matrix (array_1) to match the new order of the wrapped X data. That can get complicated depending on how your x data are arranaged. Assuming the x is a vector in ascending order, you can follow this demo using the data you provided in a comment below. Note that data on x=0 and x=360 will be combined after wrapping.
long = D1.long;
lat = D2.lat;
sst2 = D3.sst2;
% Wrap longitudinal values and adjust order of C data according
% to the wrapped longitudinal values. This assumes the original
% longitudinal values are in ascending order.
assert(isequal(sort(long(:)), long(:)), 'This method assumes X was sorted in ascending order');
Xwrap = wrapTo180(long);
[XwrapSorted, XwrapOrder] = sort(Xwrap(:));
C = sst2(XwrapOrder,:);
% Plot original data
figure()
tiledlayout(2,1,'TileSpacing','compact')
nexttile()
pcolor(long,lat,sst2');
colorbar;
xlabel('Longitude');
ylabel('Latitude');
set(gca,'clim',[275 300]);
title('Original data ([0,360])')
axis equal
axis tight
% Plot wrapped version
nexttile()
pcolor(XwrapSorted,lat,C');
colorbar;xlabel('Longitude');ylabel('Latitude');
set(gca,'clim',[275 300]);
title('Wrapped data ([-180,180])')
axis equal
axis tight
##### 댓글 수: 6표시숨기기 이전 댓글 수: 5
Brian DeCicco 2021년 7월 28일
Hey Adam! I gave it another shot and it works perfectly now. Looks like I had a minor typo and that was the reason why I couldn't get the data to shift over with the longitude grid using your code. It works perfectly now! Thank you so much for the quick and thorough responses, it is greatly appreciated. The temperatures in the dataset are in fact the water surface temperatures in degrees Kelvin.
-Brian

댓글을 달려면 로그인하십시오.

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by