简体   繁体   English

如何在Matlab中更正ncread纬度和经度子集?

[英]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: 我将此代码与pcolorpcolor(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.

相关问题 Matlab:绘制经度和​​纬度 - Matlab : plot latitude and longitude Matlab中的经度,纬度和距离 - Longitude, latitude, and distance in Matlab 如何在Matlab中使用经度和纬度绘制按钮 - How to plot a button using longitude and latitude in matlab 如何在MATLAB中获取字符串的子集 - How do I take a subset of a string in MATLAB 如何从Matlab中的HDF文件中获取经度和纬度数据? - how to get latitude and longitude data from HDF files in matlab? 如何使用Matlab获取图像中每个像素的经度和纬度 - How to get Longitude and Latitude for each pixel in an image using Matlab 基于纬度和经度matlab的单独数据 - Separate data based on latitude and longitude matlab 将 Shapefile 导入 Matlab 后,如何使用创建的结构中的经度和纬度数据 - Once Shapefile is imported to Matlab, How to use longitude and latitude data from the created structure 在Matlab中,如何在不创建任何新变量的情况下捕获数组子集的特定列的平均值作为输出? - In Matlab, how do I capture as output the mean of a particular column of a subset of an array without creating any new variables? MATLAB函数可计算两个坐标(纬度和经度)之间的距离 - MATLAB function to calculate distance between two coordinates (latitude and longitude)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM