I want to draw pathline for two particle for a 2d problem
조회 수: 97 (최근 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
대략 16시간 전
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
대략 15시간 전
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!