How to perform interpolation on a 2D array in MATLAB

前端 未结 4 1171
再見小時候
再見小時候 2020-12-04 02:01

How can I make a function of 2 variables and given a 2D array, it would return an interpolated value?

I have N x M array A. I need to inter

4条回答
  •  不思量自难忘°
    2020-12-04 02:24

    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
    

提交回复
热议问题