11 views (last 30 days)
Show older comments
Mark on 21 Nov 2022
-
-
Link
Direct link to this question
https://webchat.mathworks.com/matlabcentral/answers/1857663-interpolating-3d-gridded-data-in-matlab
Commented: Mark on 22 Nov 2022
Accepted Answer: Matt J
Open in MATLAB Online
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.
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Matt J on 21 Nov 2022
Edited: Matt J on 21 Nov 2022
Open in MATLAB Online
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 Comments Show 9 older commentsHide 9 older comments
Show 9 older commentsHide 9 older comments
Mark on 21 Nov 2022
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1857663-interpolating-3d-gridded-data-in-matlab#comment_2475818
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
Matt J on 21 Nov 2022
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1857663-interpolating-3d-gridded-data-in-matlab#comment_2475828
Edited: Matt J on 21 Nov 2022
Open in MATLAB Online
Thanks @Matt J for your asistance here. Code is working now.
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});
Mark on 21 Nov 2022
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1857663-interpolating-3d-gridded-data-in-matlab#comment_2475853
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).
Matt J on 21 Nov 2022
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1857663-interpolating-3d-gridded-data-in-matlab#comment_2475873
Edited: Matt J on 21 Nov 2022
Open in MATLAB Online
Same thing.
[LATS,LONGS,HEIGHTS]=deal(LUT.GridVectors{:});
Point1=LUT({2,LONGS,100});
Point2=LUT({LATS,2,100});
Mark on 21 Nov 2022
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1857663-interpolating-3d-gridded-data-in-matlab#comment_2475888
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.
Matt J on 21 Nov 2022
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1857663-interpolating-3d-gridded-data-in-matlab#comment_2475903
It is not plotting. None of the code I gave you forms an actual plot.
Mark on 21 Nov 2022
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1857663-interpolating-3d-gridded-data-in-matlab#comment_2475908
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).
Matt J on 21 Nov 2022
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1857663-interpolating-3d-gridded-data-in-matlab#comment_2476368
Edited: Matt J on 21 Nov 2022
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.
Mark on 22 Nov 2022
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1857663-interpolating-3d-gridded-data-in-matlab#comment_2477643
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.
Matt J on 22 Nov 2022
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1857663-interpolating-3d-gridded-data-in-matlab#comment_2477708
Edited: Matt J on 22 Nov 2022
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.
Mark on 22 Nov 2022
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1857663-interpolating-3d-gridded-data-in-matlab#comment_2477723
Many thanks @Matt J.
Sign in to comment.
More Answers (0)
Sign in to answer this question.
See Also
Categories
MATLABMathematicsInterpolationInterpolating Gridded Data
Find more on Interpolating Gridded Data in Help Center and File Exchange
Tags
- interpolation
- 3d
- interpn
- griddedinterpolant
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- 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
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office