Resampling non-uniformly sampled 2D Surface

조회 수: 22 (최근 30일)
Ranjan Sonalkar
Ranjan Sonalkar 2020년 12월 24일
댓글: Star Strider 2020년 12월 29일
I have a 2D surface that is created from orthographic transformation of uniformly sampled surface in latitude/longitude coordinates. So, the transformed surface is non-uniformly sampled in orthographic coordinates (x, y). I would like to resample it to a specific uniform resolution in the orthographic axes.
Is there a function that can do this?
  댓글 수: 4
Ranjan Sonalkar
Ranjan Sonalkar 2020년 12월 29일
It looks like all I need is griddata, since I already have the desired uniformly spaced vectors, x, y at which I want the surface to be sampled at. x,y, are the nonuniformly sampled vectors and Z is the corresponding matrix of surface values. So, it appears that the following three lines of code will do the job.
[X, Y] = meshgrid(x, y);
[Xq,Yq] = meshgrid(x_i, y_i); % Create Interpolation Matrices With Uniform Grid Spacing
ZqNatural = griddata(X, Y, Z, Xq, Yq, 'natural'); % Interpolate Matrices To New Regular Grid - natural
Star Strider
Star Strider 2020년 12월 29일
That will work!
There was a bit of a discrepancy between the title of your post: Resampling non-uniformly sampled 2D Surface and ‘... orthographic transformation of uniformly sampled surface ...’ so I went with the non-uniform situation in my Answer, because it will cover both possibilities.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2020년 12월 24일
Not a single function, however there are a group of functions that used in concert can do it.
Try this example:
x = sort(rand(1, 10))*10; % Latitude Vector
y = sort(rand(1, 12))*10; % Longitude Vector
[X,Y] = meshgrid(x, y); % Create Matrices
Z = sin(X*pi/2) .* cos(Y*pi/2); % Create Matrices
figure
surf(x, y, Z)
xlabel('x')
ylabel('y')
zlabel('Z')
title('Surface With Non-Uniform Grid Spacing')
xv = linspace(min(x), max(x), 40); % Create New Uniformly-Spaced Vector From Original ‘x’
yv = linspace(min(y), max(y), 50); % Create New Uniformly-Spaced Vector Vector From Original ‘y’
[Xq,Yq] = ndgrid(xv, yv); % Create Interpolation Matrices With Uniform Grid Spacing
Zq = griddata(X(:),Y(:),Z(:), Xq, Yq, 'natural'); % Interpolate Matrices To New Regular Grid
figure
surf(Xq, Yq, Zq)
xlabel('Xq')
ylabel('Yq')
zlabel('Zq')
title('Interpolated Surface With Uniform Grid Spacing')
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by