[英]How do I correct ncread subset of latitude and longitude in Matlab?
I am trying to subset a .nc file in Matlab using ncread
. 我正在尝试使用ncread
在Matlab ncread
集.nc文件。 I am looking to subset the data for longitudes -74.6875 to -10.3125 (W) and latitudes 58.2500 to 84.7500 (N) to create a bounding box around Greenland. 我正在寻找数据的子集,以经度-74.6875至-10.3125(W)和纬度58.2500至84.7500(N)创建一个围绕格陵兰岛的边界框。 I want the subset for every day of data. 我想要每天的数据子集。 I tried the following code, which works for the indices of longitude and latitude that I need, but produces a flipped (upside down) version of Greenland (see attached 1 ): 我尝试了以下代码,该代码适用于我需要的经度和纬度的索引,但是会产生格陵兰岛的翻转版本(倒置)(请参阅附件1 ):
data = ncread('dust_ddep.nc','dust_ddep',[457 297 1], [104 54 Inf], [1 1 1]); %576x360x366 lon, lat, time
When I try to plot the data, I need to flip it to make sure that Iceland dust is located in the right place geographically (see attached). 当我尝试绘制数据时,我需要翻转它以确保冰岛的灰尘在地理上位于正确的位置(请参阅附件)。 The latitude is plotted inversely (needs to be from 55 to 85 N, not the other way around). 纬度以相反的方式绘制(需要从55到85 N,而不是相反)。
Then, I plot using m_coast
function to produce the coastline of Greenland (see attached, 2 ): 然后,我使用m_coast
函数进行绘制以m_coast
格陵兰的海岸线(请参见附件2 ):
figure;
data1 = data(:,:,160); %Grab one day of data
imagesc(long1_sub,lat,data1)
% m_pcolor(lon,lat,data(:,:,1)); %This comes up blank when I try to run m_pcolor
shading flat; hold on;
gland = m_coast('patch',[1 1 1],'edgecolor','k')
% flipud(gland) %doesn't fix the upside down Greenland
m_grid('box','fancy');
What am I doing wrong? 我究竟做错了什么? Is it the order of my start and count? 是我开始和计数的顺序吗? Or, is it in the way that I plot imagesc? 还是以我绘制图像的方式? I tried also using pcolor
(not m_pcolor), but I receive an error saying the dimensions are wrong (but they are not ...). 我也尝试过使用pcolor
(不是m_pcolor),但是我收到一条错误消息,指出尺寸错误(但它们不是...)。 I used this code with pcolor
: pcolor(long1_sub,lat,data1)
And receive the error: 我将此代码与pcolor
: pcolor(long1_sub,lat,data1)
并收到错误:
Error using pcolor (line 59)
Matrix dimensions must agree.
The dimensions for these variables are: 这些变量的尺寸为:
Long1_sub is [104x1]
lat is [54x1]
data1 is [104x54]
The origin for imagesc is the top left corner instead of the bottom left, which therefore would 'flip' your y-axis. imagesc的原点是左上角而不是左下角,因此将“翻转”您的y轴。 So you need to flip the y axis to make it like you would normally expect. 因此,您需要翻转y轴以使其像通常期望的那样。
imagesc(long1_sub,flipup(lat),data1)
imagesc of very unintuitive because of this so I recommend using pcolor. 因此,images非常不直观,因此我建议使用pcolor。 As for why pcolor errors when using the same variables, the pcolor documentation says that, "If X and Y are vectors, X corresponds to the columns of C and Y corresponds to the rows." 至于为什么使用相同变量时pcolor错误,pcolor文档说:“如果X和Y是向量,则X对应于C的列,而Y对应于行”。 Since data1 is 104x54, you would want to transpose it to 54x104 so that it agrees with the lon/lat, 由于data1为104x54,因此您需要将其转置为54x104,以便与lon / lat一致,
pcolor(long1_sub,lat,data1') % Notice the ' next to data1
I hope this helps! 我希望这有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.