2D Interpolation of data

4 次查看(过去 30 天)
Hi..I was trying to perform a 2D-interpolation for 2 data files. The file AOA0_u600 contains data of nodenumber, x-coordinate, y-coordinate, z-coordinate and pressure.
The file Y-600 contains data of entity id, x-coordinate, y-coordinate and z-coordinate. Both the files contain the data for the same Y-coordinate.
Basically the idea was to interpolate the value of pressure at the values of x and z coordinate (sample points of 1st file) to the values of x and z-coordinate (query points of the 2nd file)
However,when using the interp2 function to interpolate the values, i was recieving the following error
%Error using griddedInterpolant
The grid vectors must be strictly monotonically increasing.
%Error in interp2>makegriddedinterp (line 229)
F = griddedInterpolant(varargin{:});
%Error in interp2 (line 129)
F = makegriddedinterp({X, Y}, V, method,extrap);
Could anyone please guide me as to how to resolve this issue?
clear all;
clc;
fid=fopen('AOA0_u600.txt');
a=textscan(fid, '%f %f %f %f %f', 'HeaderLines', 1);
b=cell2mat(a);
c=sortrows(b,2);
x=c(:,2);
x=x+0.275;
y=c(:,4);
z=c(:,5);
fid =fopen('Y-600.txt');
A=textscan(fid, '%f %f %f %f', 'HeaderLines', 12);
B=cell2mat(A);
C=sortrows(B,2);
X=C(:,2);
X1=X/1000;
Y=C(:,4);
Y1=Y/1000;
D=interp2(x,y,z,X1,Y1);

采纳的回答

Bruno Luong
Bruno Luong 2022-8-7
编辑:Bruno Luong 2022-8-7
You have scattered data, you should use scatteredInterpolant or similar, not interp2.
  3 个评论
Bruno Luong
Bruno Luong 2022-8-8
编辑:Bruno Luong 2022-8-8
No it is NOT totally correct in 2D it requires Gridded data which is "A set of points that are axis-aligned and ordered".
Such grid data can be generated by meshgrid or ndgrid command with both linear grid points strickly monotonics.
Akarsh Shetty
Akarsh Shetty 2022-8-9
编辑:Akarsh Shetty 2022-8-9
Alright..I'll keep that in mind!
The scatteredInterpolation Function worked for interpolating the scattered data from the file Y-2010.txt to the file Y_2010. However, i couldnt figure out the logic for the for loop for interpolating similar set of files.
Could you please guide me as how to proceed forward
clear all;
clc;
fid=fopen('Y_2010.txt');
a=textscan(fid, '%f %f %f %f %f', 'HeaderLines', 1);
b=cell2mat(a);
a_u=b(1:68,:);
a_l=b(69:end,:);
x_u=a_u(:,2);
x_u=x_u+0.275;
y_u=a_u(:,4);
z_u=a_u(:,5);
x_l=a_l(:,2);
x_l=x_l+0.275;
y_l=a_l(:,4);
z_l=a_l(:,5);
fid =fopen('Y-2010');
A=textscan(fid, '%f %f %f %f', 'HeaderLines', 12);
B=cell2mat(A);
au=B(B(:,4) >= -440.026398,:);
al=B(B(:,4) < -440.026398,:);
X_U=au(:,2);
X1=X_U/1000;
Y_U=au(:,4);
Y1=Y_U/1000;
M=[X1,Y1];
N=sortrows(M,1);
X_L=al(:,2);
X2=X_L/1000;
Y_L=al(1:63,4);
Y2=Y_L/1000;
O=[X2,Y2];
P=sortrows(O,1);
F=scatteredInterpolant(x_u,y_u,z_u);
G=scatteredInterpolant(x_l,y_l,z_l);
vq=F(N(:,1),N(:,2));
wq=G(P(:,1),P(:,2));
plot(x_u,z_u,'-o');
hold on
plot(x_l,z_l,'-r');
hold on
plot(N(:,1),vq);
hold on
plot(P(:,1),wq);
Q=[N,vq];
R=[P,wq];
dlmwrite('Y_2010_I',[Q;zeros(1,3);R],'delimiter','\t','precision','%f');

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by