Interpolating 3D Gridded Data in Matlab
显示 更早的评论
I have a 3D gridded data and I want to interpolate to increase the size of the data. Current resolution is 5 deg long x 5 deg latitude and I want to change the resolution to 2 deg long x 2 deg latitude as I am interested in Lat = 2 deg. The dimension of the data is (Longitude x Latitude x Height) and current size is (72x36x40).
Long= 72x36x40
Lat = 72x36x40
Height =72x36x40
Temperature =72x36x40
I tried to use the interpn function but at the end I am only getting NaN values. Below are my codes.
file='data.nc';
Lat1 = ncread(file,'Latitude'); % Size is 72x36x40
Long1 = ncread(file1, 'Longitude'); % Size is 72x36x40
Height = ncread(file1,'Height'); % Size is 72x36x40
Temp1 = ncread(file,'Temperature'); % Size is 72x36x40
[LongI,LatI,HeightI] = ndgrid(0:5:360,-90:5:90,0:10:600);
TempI = interpn(Long1,Lat1,Height,Temp1,LongI,LatI,HeightI,'linear');`
My goal is to convert 3D data at 5 long x 5 lat resolution to 2 long x 2 lat resolution.
采纳的回答
This might be easier:
LUT= griddedInterpolant(Long1,Lat1,Height,Temp1,'linear','linear'); %create interp object
newgrid=LUT.GridVectors;
newgrid(1:2)=cellfun(@(z) z(1):2:z(end) , newgrid(1:2),'uni',0); %change the sampling lattice in the first two coordinates to be increments of 2
TempI = LUT(newgrid); %interpolate on newgrid
11 个评论
Thanks @Matt J for your asistance here. Code is working now. Maybe if you could comment in your code so that I can get better sense out of it. Could you also advise how I will be able to take a slice at a particular latitude and longitude in TempI data.
I am interested in taking a slice at Lat= 2 degrees and Long = 2 degrees
I'm glad. Could you Accept-click the answer to indicate so?
I am interested in taking a slice at Lat= 2 degrees and Long = 2 degrees
At what heights? If at all the heights originally sampled, then,
Heights=LUT.GridVectors{3};
slice=LUT({2,2,Heights});
Thanks @Matt J. I should have been more specific. Actually, I want to take a slice at two specific point
Point one: Lat = 2 degrees and height = 100 km.
Point two: Long = 2 degrees and height = 100km.
My orignal latitude varies in a increment of 5 degrees from -90 to +90 i.e (-90:5:90).
Same thing.
[LATS,LONGS,HEIGHTS]=deal(LUT.GridVectors{:});
Point1=LUT({2,LONGS,100});
Point2=LUT({LATS,2,100});
Thank you so much. Is there a way to check if it is plotting at these points i.e can we see all these new gridded data like Lat, Long, Height and Temp in 2 deg long x 2 degree lat.
It is not plotting. None of the code I gave you forms an actual plot.
I meant how to check if this point (Point1=LUT({2,LONGS,100})) actually crosspond to Lat = 2 degree and Height =100 km. Can we read or see all the parameters (Long, Lat, Height and Temp).
I meant how to check if this point (Point1=LUT({2,LONGS,100})) actually crosspond to Lat = 2 degree and Height =100 km. Can we read or see all the parameters (Long, Lat, Height and Temp).
Well, {Long,Lat,Height} are what we are specifying as input in the form {2,LONGS,100}. So, I don't know what you mean by "checking" it. It is something that we provided and which can be directly inspected. The temperature values are contained in the output Point1.
If you have reason to believe that LUT did not do the interpolation correctly when computing Point1, you have to say what sort of independent test would reassure you.
Or, do you mean you just want to retrieve the underlying data that is being interpolated? That is contained in LUT.GridVectors and LUT.Values.
Thanks @Matt J. I would like to retrieve the data that are been interpolated. All of the original data (Long, Lat,Height, Temp) are in a resolution of 5 long x 5 lat and I would like to increase the resolution of the data so that the resolution of the new data is 2 long x 2 lat. The dimension of the data is long x lat x height and I only want to change the size of long and lat. After interpolation I want to access or read all of my new data like long, lat, height and Temp so that I can do some plotting.
That was given in my original answer. After the upsampling to 2 long x 2 lat, the upsampled {long,lat,height} are in newgrid, while the upsampled temperatures are in TempQ.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息
另请参阅
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
