I want to draw pathline for two particle for a 2d problem
96 次查看(过去 30 天)
显示 更早的评论
I have the results for the space and velocity variables xn, yn, un, vn all in 50*300*2085 dimensions. My space points xn,yn are changing with time along with un, vn. I tried to write the following
M = size(xn,1); N = size(xn,2); Nt = size(xn,3);
dt = 5*0.005; % need to be same as the data stored
% target point index
X0 = [0 0 ]; Y0 = [1.5 -1.5];
plot(X0,Y0,'r*','LineWidth',1); hold on;
for i = 1 : length(X0)
X(i) = X0(i); Y(i) = Y0(i);
for n = 1 : Nt
x = xn(:,:,n); y = yn(:,:,n);
u = un(:,:,n); v = vn(:,:,n);
F = griddedInterpolant(x,y,u,"spline","spline");
U = F(X(i),Y(i));
F1 = griddedInterpolant(x,y,v,'spline','spline');
V = F1(X(i),Y(i));
X(i) = X(i) + dt*U; Y(i) = Y(i) + dt*V;
XX(i,n) = X(i); YY(i,n) = Y(i);
end
end
plot(XX(i,:),YY(i,:),'b','LineWidth',1.2); hold on;
But end up with the error
'Error using griddedInterpolant
Grid arrays must have NDGRID structure.'
Can you please help me with this?
0 个评论
采纳的回答
Walter Roberson
about 16 hours 前
When you use griddedInterpolant, then your x must have all of its columns the same, and the row values must be sorted. Your y must have all of its rows the same and the column values must be sorted.
[X,Y] = ndgrid(1:3, 4:7)
Here, X and Y are valid for griddedInterpolant(X,Y,V)
X(2,2) = 2.01; X(2,3) = 2.02; X(2,4) = 2.03
This X is not valid for griddedInterpolant because the columns are not all the same as each other.
There is a different major sorting order,
[X2, Y2] = meshgrid(1:3, 4:7)
For this arrangement, all of the rows of X2 are the same as each other and the columns are sorted.
These two orders are connected by
[Y3,X3] = meshgrid(4:7, 1:3);
X3, Y3
Anyhow, this "meshgrid" arrangement of data is not valid for griddedInterpolant.
Generally speaking, if you have meshgrid data, then you can
F = griddedInterpolant(x.',y.',u.',"spline","spline");
3 个评论
Walter Roberson
about 15 hours 前
F = scatteredInterpolant(xy, u, "linear", "linear");
would be more natural. On the other hand scatteredInterpolant does not handle spline.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Splines 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!