Interpolation for 1-D, 2-D, 3-D, and N-D gridded data in functionformat
1 次查看(过去 30 天)
显示 更早的评论
I have an N-D gridded data and I want to fit a hyperplane on them. There are two almost similar commends in Matlab but none of them is the one I'm looking for. The following function is almost the one I'm looking for but it works just for 2D (line) and 3D (surface); however, I'm looking for N-Dimension https://www.mathworks.com/help/curvefit/fit.html Another command might be useful but still is not the exact one I'm looking for is interpn. Although it works for N-D, it is not gerenate a black box or fucntion as the way you can input value and have the output. https://www.mathworks.com/help/matlab/ref/interpn.html
In this regard and all the explanations above, do you know how I can address this issue? Thanks
0 个评论
回答(2 个)
Stephen23
2018-1-3
编辑:Stephen23
2018-1-3
ND curve-fitting is not really a trivial task. You can easily define a "black box or fucntion as the way you can input value and have the output" by defining an anonymous function which contains interpn, e.g.:
>> [X1,X2] = ndgrid((-5:1:5));
>> R = sqrt(X1.^2 + X2.^2)+ eps;
>> V = sin(R)./(R);
>> fun = @(q1,q2)interpn(X1,X2,V,q1,q2,'cubic');
>> fun([1,2;3,4],[0,0;1,1])
ans =
0.84147 0.45465
-0.0065407 -0.20163
0 个评论
Matt J
2018-1-3
编辑:Matt J
2018-1-3
Your question isn't terribly clear. Fitting and interpolation are two very different things. I suspect what you might be looking for is lsqcurvefit(). It will let you fit parameters to an N-dimensional black-box function. However, hyperplanes are especially simple functions. If you are merely trying to fit an N-dimensional hyperplane given M data points organized into an MxN array A, it can be done by very simple linear algebra:
d=mean(A,1);
[~,~,V]=svd(A-d,0);
hyperplaneNormal=V(:,end);
hyperplaneShift=d*hyperplaneNormal;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!