Interpolating 3D Gridded data at specific cordinates

I am working with 3D gridded data with a dimension of (Longitude,Latitude,Height) and size (73x37x41). I want to plot temperature vs longitude at a slice of latitude = 0 degree and Height at 100 km and also temperature vs latitude at a slice of longitude = 0 degrees and height = 100 km.The original data does not provide data at these specific point i.e ( latitude = 0 and height = 100 km and longitude= 0 degree and height = 100 km). I know I have to interpolate my data to plot at these specific point but I am having problem in interpolating.
My data is something like this
[Long,Lat,Height] = ndgrid(0:5:360,-90:5:90,0:15:600);
Temp = rand(73,37,41)*1000;

 Réponse acceptée

Matt J
Matt J le 22 Nov 2022
Modifié(e) : Matt J le 22 Nov 2022
[Long,Lat,Height] = deal(0:5:360,-90:5:90,0:15:600); %Fake data
Temp = rand(73,37,41)*1000;
LUT=griddedInterpolant({Long,Lat,Height}, Temp); %interpolation object
TempvLong=LUT({0,Long,100}); %slices
TempvLat=LUT({Lat,0,100});
figure(1)
plot(Long(:),TempvLong(:));
xlabel 'Longitude'; ylabel 'Temperature'
figure(2);
plot(Lat(:),TempvLat(:));
xlabel 'Latitude'; ylabel 'Temperature'

6 commentaires

Thanks again @Matt J
Hi Matt, the plots remain same if I try to plot at two different (Height = 100 km and 500 km. Like the plots for Long(:) vs TempvLong=LUT({0,Long,100}); and Long(:) vs TempvLong=LUT({0,Long,500} is same which is not realistic from the data. Can you check why this is happening.
I don't see it in my test below:
[Long,Lat,Height] = deal(0:5:360,-90:5:90,0:15:600); %Fake data
Temp = rand(73,37,41)*1000;
LUT=griddedInterpolant({Long,Lat,Height}, Temp); %interpolation object
tiledlayout(1,2)
nexttile
TempvLong=LUT({0,Long,100}); %slices
plot(Long(:),TempvLong(:));
xlabel 'Longitude'; ylabel 'Temperature'
nexttile
TempvLong=LUT({0,Long,500}); %slices
plot(Long(:),TempvLong(:));
xlabel 'Longitude'; ylabel 'Temperature'
Mark
Mark le 22 Nov 2022
Modifié(e) : Matt J le 22 Nov 2022
From my actual data the two plots are same at two different heights. I am uploading the link for my data:
Link: shorturl.at/fghNP
My Matlab code is below:
file='data.nc';
Temp = ncread(file1,'Temperature');
Lat = ncread(file1,'Latitude')*(180/pi);% convert rad to degrees
Long = ncread(file1, 'Longitude')*(180/pi);% convert rad to degrees
Alt= ncread(file1,'Altitude');
Temp= double(Temp); %convert from single to double
Long =double(Long);
Lat = double(Lat);
Alt= double(Alt);
Long = Long(:,1,1)';
Lat = Lat(1,:,1);
Alt = Alt(1,1,:);
Alt = permute(Alt,[1 3 2]);
LUT=griddedInterpolant({Long,Lat,Alt}, Temp); %interpolation object
tiledlayout(1,2)
nexttile
TempvLong1=LUT({0,Long,100}); %slices
plot(Long1(:),TempvLong1(:));
xlabel 'Longitude'; ylabel 'Temperature'
nexttile
TempvLong2=LUT({0,Long,500}); %slices
plot(Long(:),TempvLong2(:));
xlabel 'Longitude'; ylabel 'Temperature'
Both 100 and 500 are well outside the range of Alt values given, and are in different units, so LUT is just doing meaningless extrapolation.
>> mnmx(Alt)
Maximum entry = 664122.1875
Minimum entry = 96420.9922
NaNs Present = NO
Thanks, @Matt J. I figured out where I was wrong.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by