Interpolating data to get values at specific depth

조회 수: 4 (최근 30일)
Luís Henrique Bordin
Luís Henrique Bordin 2024년 2월 23일
댓글: Luís Henrique Bordin 2024년 2월 23일
Dear experts, please help. I was searching and trying for anentire day and I couldn't figure it out by my own.
I have X, Y, Z, data.
X is longitude, Y is latitude, Z is depth, and data is temperature for example.
X and Y are 2D matrices (224x164). Z and data are 3D matrices (224x164x37).
The depth is unevenly spaced, for exemple, 1.0, 2.3, 5.6, 8.3 and so on, but I need the values of temperature exactly at 5m for example.
What I need is to get the data values at a specif depth all over the domain to plot a colored 2D map.
Please, could someone help me on how is such interpolation?
P.S. I know how to plot, I did it by plotting the surface Z(:,:,1), but as I mentioned, I need other depth layer.
Thank you so much in advance!

채택된 답변

Torsten 2024년 2월 23일
편집: Torsten 2024년 2월 23일
Make X and Y also 224x164x37 (just by repeating the planar profile 37 times) and use interp3 to interpolate to the depth of your choice.
Then make your contourf or surf plot.
  댓글 수: 5
Torsten 2024년 2월 23일
편집: Torsten 2024년 2월 23일
I guess your data will be well-behaved.
This code only takes the temperature data at the point (X(i,j),Y(i,j)) over the 37 heights and makes a 1d-interpolation to the required height (0.5 m) for all these points. I don't know if the results get better if you include temperatures in neighbouring points, but the interpolation will become more complicated. You will most probably have to use "ScatteredInterpolant".
X = rand(224,164); % random X-coordinates
Y = rand(224,164); % random Y-coordinates
Z = 10*rand(224,164,37); % random heights at points (X,Y)
data = 20 + rand(224,164,37)*20; % random temperatures at points (X,Y,Z)
h = 5; % interpolation level
for i = 1:224
for j = 1:164
[z,idx] = sort(squeeze(Z(i,j,:)));
d = squeeze(data(i,j,idx));
temp_5(i,j) = interp1(z,d,h);
Luís Henrique Bordin
Luís Henrique Bordin 2024년 2월 23일
Now it worked perfectly. Thank you very much, Torsten! Best!

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

추가 답변 (1개)

William Rose
William Rose 2024년 2월 23일
x=(0:10); y=(0:11)'; z=[1.0, 2.3, 5.6, 8.3]; % vectors x,y,z
%Make data() with desired dimensions, same at each depth
% Make data different at different depths
for k=1:length(z), data(:,:,k)=data(:,:,k)+z(k)^2/10; end
% check that the array sizes are as desired
fprintf('Size X, Y, Z= %dx%d, %dx%d, %dx%dx%d.\n',size(X),size(Y),size(data))
Size X, Y, Z= 12x11, 12x11, 12x11x4.
% Plot data(x,y,z=5.6), as a test
grid on; xlabel('X'); ylabel('Y'), zlabel('Data'); title('Data(:,:,z=5.6)')
data5=zeros(size(X)); % allocate array for data interpolated to z=5
for i=1:length(y), for j=1:length(x)
end, end
% Plot data(x,y,z=5)
grid on; xlabel('X'); ylabel('Y'), zlabel('Data');
title('Data, Interpolated to z=5')


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