如何在MATLAB中对2D数组执行插值 [英] How to perform interpolation on a 2D array in MATLAB

查看:163
本文介绍了如何在MATLAB中对2D数组执行插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使2个变量组成一个函数并给定2D数组,它将返回一个插值?

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中对2D数组执行插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆