Table lookup based on 3 variables
조회 수: 3 (최근 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에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!