本文介绍了如何在 MATLAB 中对二维数组执行插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何制作一个包含 2 个变量的函数并给定一个二维数组,它会返回一个内插值?
How can I make a function of 2 variables and given a 2D array, it would return an interpolated value?
我有 N x M
数组 A
.我需要对它进行插值并以某种方式获得该表面的函数,以便我可以选择非整数参数的值.(我需要将该插值用作 2 个变量的函数)
I have N x M
array A
. I need to interpolate it and somehow obtain the function of that surface so I could pick values on not-integer arguments.(I need to use that interpolation as a function of 2 variables)
例如:
A[N,M] //my array
// here is the method I'm looking for. Returns function interpolatedA
interpolatedA(3.14,344.1) //That function returns interpolated value
推荐答案
对于常规网格上的数据,请使用 interp2.如果您的数据分散,请使用 griddata.您可以创建一个 匿名函数 作为这些函数的简化包装器电话.
For data on a regular grid, use interp2. If your data is scattered, use griddata. You can create an anonymous function as a simplified wrapper around those calls.
M = 10;
N = 5;
A = rand(M,N);
interpolatedA = @(y,x) interp2(1:N,1:M,A,x,y);
%interpolatedA = @(y,x) griddata(1:N,1:M,A,x,y); % alternative
interpolatedA(3.3,8.2)
ans =
0.53955
这篇关于如何在 MATLAB 中对二维数组执行插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!