Table lookup based on 3 variables

8 vues (au cours des 30 derniers jours)
John
John le 26 Juin 2019
Modifié(e) : Stephen23 le 27 Juin 2019
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
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.
John
John le 27 Juin 2019
Hi John & Stephen,
Appreciate you both looking into my issue. I am going for a solution that allows for interpolation between points, not just a lookup on values contained in the data sets so I do not think the first solution is appropriate.
The second solution made me go back and review my code and it does indeed agree with what you are saying.
My original question had A, B, C, D vectors as an example and the data in them is not th actual datasets I am using. My apologies for the confusion.
For consistancy of this question, let's say.
C: [-12 23 9 -400 62 -1]
D: [1:6]
E: [10:10:60]
F: [-1 -14 -16 -200 -30 -10]
Now that my outputs have been created, I want to be able to interpolate between values of A, B and C to find values of D, E, & F. Another desire is to create a human readable table of the newly gridded data. Are either of these possible? My inclination is the interpolation should be but creating a 2-D table from a 3-D grid wouldn't be.

Connectez-vous pour commenter.

Réponses (0)

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!

Translated by