How can I interpolate different dimension array on a common grid?
이전 댓글 표시
Hi everybody,
I find myself with spatialized data coming from different sources that I'd like to compare by interpolating them on a common grid, but I still don't understand how.
I have two sets of data of Longitude, Latitude, Altitude and a scalar value: in the first set all of these variables are vectors (1 row * n columns), while in the second set they are n-dimensional matrixes (for Longitude I have a matrix of m rows * n column * p layers having a longitude value for each [m,n,p] point in this "cube", the same goes for Latitude, ...).
I would like to use the minima and maxima of values of Longitude, Latitude and Altitude to create a common 3D grid on which to interpolate the scalar values.
I can give an example of two different datasets and the steps I did until now along with how I used Matlab's grid interpolation functions (dataset values are purely fictional and way much bigger, it's just to have an example).
Dataset 1:
Lon = [-0.98 -0.97 -0.96] % degrees
Lat = [44.1 44.2 44.3] % degrees
Alt = [380 400 450] % meters
Scal = [22.2 35 40] % concentration
Dataset 2:
Lon=[-0.982 -0.981;-0.980 -0.975;-0.970 -0.965] % degrees
Lat= [44.09 44.10;44.11 44.22;44.24 44.23] % degrees
Alt(:,:,1)= [320.2 330;327 350;322 327] % meters
...
Alt(:,:,4)= [470 447.1;475 480;477 450] % meters
% Again Scal is a m*n*p matrix where p is equal to 4.
Since Dataset 2 is the one with the most widely spanning data, I've constructed a grid on the basis of those data using ndgrid:
MinLat=min(min(Lat));
MaxLat=max(max(Lat));
StepLat=abs(MaxLat-MinLat)/100;
MinLon=min(min(Lon));
MaxLon=max(max(Lon));
StepLon=abs(MaxLon-MinLon)/100;
MinAlt=min(min(Alt(:,:,1));
MaxAlt=max(max(Alt(:,:,3));
StepAlt=abs(MaxAlt-MinAlt)/100;
LonQueryPoints=MinLon:StepLon:MaxLon;
LatQueryPoints=MinLat:StepLat:MaxLat;
AltQueryPoints=MinAlt:StepAlt:MaxAlt;
Grid=ndgrid(LonQueryPoints,LatQueryPoints,AltQueryPoints);
Grid is now a 100*100*100 matrix made by the query points of Longitude, Latitude and Altitude and it's where I'd like to interpolate my scalar values and I've tried it using the "griddedInterpolant" Matlab function:
% Applied to Dataset 2:
Scalar_Interpolation=griddedInterpolant(Grid,Scal(:,:,1:4))
And I receive the error:
1D Interpolation requires vector input for X and V
Probably I'm not understanding correctly how to employ the griddedInterpolant function, or, maybe, the griddedInterpolant is only able to handle m*n*1 matrixes.
댓글 수: 6
Is this similar to the recent question from Gavin on lat, lon interpolation? It seems awfully close if not.
Do these data actually span the ranges or are they, like Gavin's, lacking information on one or more boundaries so that in fact one needs to extrapolate mostly instead of interpolate?
A small sample but representative data set would likely help to envision the situation more precisely.
dpb
2013년 12월 15일
Indeed griddedinterpolant is for 2D data only; you'd have to do each plane independently. The only builtin for 3D is interp3 which needs plaid input a la ndgrid
You might check on the File Exchange for more flexible routines. In your case since it appears you are in fact interpolating within a grid, it should work. The other posting I referred to wasn't so lucky...
Federico
2013년 12월 16일
dpb
2013년 12월 16일
It appeared to me you could use interp3 on the one dataset to obtain points at the locations of the other. It wasn't/isn't totally clear to me what your meaning of compare is here.
dpb
2013년 12월 19일
See the other thread I mentioned wherein the input values were rearranged in ascending order--seems same idea should work here.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!