Interpolating 3D Gridded data at specific cordinates (2024)

2 views (last 30 days)

Show older comments

Mark on 22 Nov 2022

  • Link

    Direct link to this question

    https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates

  • Link

    Direct link to this question

    https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates

Commented: Mark on 22 Nov 2022

Accepted Answer: Matt J

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;

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Matt J on 22 Nov 2022

  • Link

    Direct link to this answer

    https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#answer_1107643

  • Link

    Direct link to this answer

    https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#answer_1107643

Edited: Matt J on 22 Nov 2022

Open in MATLAB Online

[Long,Lat,Height] = deal(0:5:360,-90:5:90,0:15:600); %Fake data

Temp = rand(73,37,41)*1000;

TempvLong=LUT({0,Long,100}); %slices

TempvLat=LUT({Lat,0,100});

figure(1)

plot(Long(:),TempvLong(:));

xlabel 'Longitude'; ylabel 'Temperature'

Interpolating 3D Gridded data at specific cordinates (3)

figure(2);

plot(Lat(:),TempvLat(:));

xlabel 'Latitude'; ylabel 'Temperature'

Interpolating 3D Gridded data at specific cordinates (4)

6 Comments

Show 4 older commentsHide 4 older comments

Mark on 22 Nov 2022

Direct link to this comment

https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#comment_2477933

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#comment_2477933

Thanks again @Matt J

Mark on 22 Nov 2022

Direct link to this comment

https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#comment_2477938

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#comment_2477938

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.

Matt J on 22 Nov 2022

Direct link to this comment

https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#comment_2477948

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#comment_2477948

Open in MATLAB Online

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'

Interpolating 3D Gridded data at specific cordinates (8)

Mark on 22 Nov 2022

Direct link to this comment

https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#comment_2478268

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#comment_2478268

Edited: Matt J on 22 Nov 2022

Open in MATLAB Online

Hi @Matt J,

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'

Matt J on 22 Nov 2022

Direct link to this comment

https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#comment_2478513

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#comment_2478513

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

Mark on 22 Nov 2022

Direct link to this comment

https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#comment_2479663

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/1858918-interpolating-3d-gridded-data-at-specific-cordinates#comment_2479663

Thanks, @Matt J. I figured out where I was wrong.

Sign in to comment.

More Answers (0)

Sign in to answer this question.

See Also

Categories

SimulinkBlock and Blockset AuthoringAuthor Block Masks

Find more on Author Block Masks in Help Center and File Exchange

Tags

  • interpolation

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.


Interpolating 3D Gridded data at specific cordinates (12)

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)

Europe

  • 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

Contact your local office

Interpolating  3D Gridded data at specific cordinates (2024)
Top Articles
Latest Posts
Article information

Author: Golda Nolan II

Last Updated:

Views: 5700

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Golda Nolan II

Birthday: 1998-05-14

Address: Suite 369 9754 Roberts Pines, West Benitaburgh, NM 69180-7958

Phone: +522993866487

Job: Sales Executive

Hobby: Worldbuilding, Shopping, Quilting, Cooking, Homebrewing, Leather crafting, Pet

Introduction: My name is Golda Nolan II, I am a thoughtful, clever, cute, jolly, brave, powerful, splendid person who loves writing and wants to share my knowledge and understanding with you.