Why do I receive NaN from GRIDDATA when there's no NaN in the input in MATLAB R2013b (8.2)?
25 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 13 Jun. 2014
Beantwortet: MathWorks Support Team
am 13 Jun. 2014
When I run the code below, I got NaN in the last several columns of the output from GRIDDATA. Is there anything wrong in my code?
e = ...
[201.393814086914 82.2774810791016 0.96469920873642 2.2019145488739 13.4432363510132 ...
0.758060276508331 0 -0.84099268913269 0 6.20107507705688 4.20095491409302 ...
4.20095491409302 5.35119485855103 1.86449265480042 0;
849.910461425781 1200 0 2.87676000595093 10.0690097808838 11.987174987793 ...
0 -1.63550007343292 0 5.90027523040771 7.03830814361572 7.03830814361572 ...
20.3102703094482 0.396224230527878 0.213999390602112;
991.704895019531 1200 66.0872955322266 284.512298583984 85.2018051147461 ...
44.9421310424805 81.4901580810547 61.1384201049805 69.4615173339844 ...
6.71358013153076 7.37573099136353 49.5474700927734 50.1098442077637 ...
43.7674751281738 28.4084148406982;
94.3122253417969 10.9749069213867 10.9749069213867 0.402327746152878 ...
3951.5849609375 0.177378296852112 0.402327746152878 0 8.06888675689697 ...
6.71358013153076 0.402327746152878 0 0 29.6456317901611 19.6354236602783 ...
;
18.8481044769287 2.45738172531128 0 0 1.20185422897339 0 1.18964719772339 ...
0 7.12528514862061 6.39398050308228 0 2.6518120765686 2.6518120765686 ...
0 0];
x = [0:0.2967:4.45];
y = [0:0.2925:1.17];
m = 0:0.001:4.45;
n = 0:0.005:1.17;
[a,b] = meshgrid(m,n);
c = griddata(x,y,e,a,b);
Akzeptierte Antwort
MathWorks Support Team
am 13 Jun. 2014
You're getting NaN values from GRIDDATA because some query points are outside the convex hull of the sample data points. GRIDDATA only supports interpolation within the convex hull. The following piece of code shows the sample data in blue and the query points in red.
[X,Y] = meshgrid(x,y);
X = X(:);
Y = Y(:);
dt = delaunayTriangulation(X,Y);
plot(a,b,'.r')
axis equal
hold on
triplot(dt);
hold off
You can use extrapolation to approximate the values outside the convex hull. scatteredInterpolant is similar to GRIDDATA, but in addition it supports extrapolation. This sample data lies on a regular grid, so the grid-based interpolation algorithms are more efficient to use here. You can use griddedInterpolant to solve this problem and this also supports extrapolation outside the domain of the grid. For example, use the following code instead:
[xq,yq] = ndgrid(x,y);
F = griddedInterpolant(xq,yq,e');
[a,b] = ndgrid(m,n);
c = F(a,b);
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!