I want to draw pathline for two particle for a 2d problem
115 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Walter Roberson
am 21 Nov. 2024 um 0:32
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");
4 Kommentare
Walter Roberson
am 21 Nov. 2024 um 19:13
I noticed that you marked that this solution did not work for you. Unfortunately you did not post any comments about what it is doing wrong for your purposes, so I do not know how to help you.
Siehe auch
Kategorien
Mehr zu Splines finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!