How can I interpolate different dimension array on a common grid?
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
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 件)
参考
カテゴリ
Help Center および File Exchange で Linear and Nonlinear Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!