Table lookup based on 3 variables
8 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to take a large set of data and first create a table based on that data then perform a lookup to find my desried values based on 3 variables of the table.
The data begins as:
A: [10 89 23 4 700 8]
B: [1 234 34 6 89 77]
C: [-12 23 9 -400 62]
D:Z: Variables that will need to be looked up (All variables have the same number of columns as A, B & C)
Then I space out the vectors A, B & C and grid them:
A_min = min(A); A_max = max(A); gridsize = 250;
a = linspace(A_min, A_max, gridsize)
b = linspace(B_min, B_max, gridsize)
c = linspace(C_min, C_max, gridsize)
[A_grid, B_grid, C_grid] = meshgrid(a, b, c)
Then I try to grid the rest of the data to form a table of all the values based on the 3 gridded variables
output_D = griddata(A', B', C', D', A_grid, B_grid, C_grid, 'linear')
Which results in a output that is all NaN
I have been successful in doing this based off 2 variables
A_min = min(A); A_max = max(A); gridsize = 250;
a = linspace(A_min, A_max, gridsize)
b = linspace(B_min, B_max, gridsize)
[A_grid, B_grid] = meshgrid(a, b)
output_D = griddata(A', B', D', A_grid, B_grid, 'linear')
3 个评论
Stephen23
2019-6-27
编辑:Stephen23
2019-6-27
"Which results in a output that is all NaN"
How did you check this? When I run your code (after a few minor bug fixes, e.g.C size, missing D, etc.), about sixteen percent of the values are not NaN:
>> numel(output_D)
ans =
15625000
>> nnz(~isnan(output_D))
ans =
2483115
Most of your grid values are outside the convex hull of the input data, which according to the griddata documentation should therefore be returned as NaN. As far as I can tell, everything is working exactly as expected and documented.
Note that you should probably use ndgrid rather that meshgrid.
Note that scatteredInterpolant is required if you want to perform extrapolation.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation of 2-D Selections in 3-D Grids 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!