Table lookup based on 3 variables
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Stephen23
le 27 Juin 2019
Modifié(e) : Stephen23
le 27 Juin 2019
"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.
Réponses (0)
Voir également
Catégories
En savoir plus sur Interpolation of 2-D Selections in 3-D Grids dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!