Run interpolation for several datasets at once
조회 수: 13 (최근 30일)
이전 댓글 표시
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
Matt J
2022년 1월 25일
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?
채택된 답변
Matt J
2022년 1월 25일
편집: Matt J
2022년 1월 25일
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));
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!