Run interpolation for several datasets at once
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
My code is performing interpolation of gridded data. My Sample values "V" are stored within an 3D array.
X and Y values are given within corresponding 3D arrays. The third dimension stores basically the different datasets (there are N different cases).
e.g.
X(:, :, 1) Y(:, :, 1) V(:, :, 1) -> Dataset 1
X(:, :, 2) Y(:, :, 2) V(:, :, 2) -> Dataset 2 (...)
The points I want to interpolate my data to (xglobal, yglobal) are constant for all Datasets.
In the end the Interpolated data is stored again within an 3D Array.
for i=1:N
x_Wake = x(:,:,i);
y_Wake = y(:,:,i);
V = Vi(:,:,i);
globaldata = griddata(x_Wake, y_Wake, Vi, xglobal, yglobal);
matV(:,:,i) = V;
end
This is part of a rountine so this step is time critical - which is the reason why I want to get rid of the loop and
Interpolate all datasets at once. I tried using griddedinterpolant - but I couldn't make it work.
Thanks in advance for any help/ ideas provided!
Best wishes
DS
5 comentarios
Matt J
el 25 de En. de 2022
It might be that they are simmilar but that depends heavily on the case which is modeled so shouldn't be taken into account too much
So, for example, the spacing between x(m,n,i) and x(m+1,n,i) is not constant with i?
Respuesta aceptada
Matt J
el 25 de En. de 2022
Editada: Matt J
el 25 de En. de 2022
x and y used to be both vectors with constant spacing (x and y have their own spacing constant). which have been meshed.
Let's forget the mesh. I will now pretend x and y are the original vectors, and likewise I will assume xglobal and yglobal are grid vectors. There is never any reason in Matlab to mesh vectors purely for the purposes of interpolation.
Nevertheless they're different from dataset to dataset (the spacing remains constant).
If so, then there is some translation vector [tx(i),ty(i)] such that for each i x and y can be written
x=x0+tx(i);
y=y0+ty(i);
Then, the interpolation loop can be done more efficiently as,
F=griddedInterpolant({x0,y0,1:N},Vi);
L=length(xglobal)
[XY,Z]=ndgrid([xglobal(:);yglobal(:)],1:N);
X=XY(1:L,:)-tx(:).';
Y=XY(l+1:end,:)-ty(:).';
matV= reshape( F([X(:),Y(:),Z(:)]) , size(Vi));
Más respuestas (1)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!