avinterpnan(A,metho​d)

バージョン 1.1.0.0 (5.29 KB) 作成者: Matt Molteno
Very straight forward interpolation (replacement) of nan's in (1D, 2D or 3D) array data.
ダウンロード: 104
更新 2016/10/8

ライセンスの表示

This function enables direct and versatile replacement of nans in your data in 1D (vectors) 2D or 3D (arrays), with a large number of available methods:
'linear' - (default) linear interpolation
'nearest' - nearest neighbor interpolation
'next' - next neighbor interpolation
'previous' - previous neighbor interpolation
'spline' - piecewise cubic spline interpolation (SPLINE)
'pchip' - shape-preserving piecewise cubic interpolation
'cubic' - same as 'pchip'
'v5cubic' - the cubic interpolation from MATLAB 5, which does not
extrapolate and uses 'spline' if X is not equally
spaced.
Note ~ some of the methods above may be unavailable in earlier versions than Matlab.

To get higher dimensional data, the results from row, column and z-direction interpolations are computed separately and then simply averaged, with surprisingly robust results (even with 'linear'). The large number of methods available are because the function uses Matlab's versatile and powerful INTERP1 command.

Here are some examples:
% % 1D:
figure;
aa=[1,2,3,5,5,4,3,2,2];
dd=sqrt(aa); % make interesting data to plot
dd(4:7)=nan; % set some of it to nan's.
ee=avinterpnan(dd); % interpolate nans.
plot(dd,'r');
hold on;
plot(ee,'bo');
title('1D example:');
legend('data with nans','new data (nans interpolated with method=''linear'', the default)','Location','Best')
hold off

% % 2D:
figure;
[aa,bb]=meshgrid([1,2,3,5,5,4,3,2,2]);
dd=(aa.*bb.*(bb+aa)).*(1/2); % make an interesting looking surface
dd(5:8,4:7)=nan; % set some of it to nan's.
ee=avinterpnan(dd); % interpolate nans.
mesh(dd);title('2D example: data with nans');
xlabel('columns');ylabel('rows');figure;
surf(ee);title('2D example: new data (nans interpolated with method=''linear'', the default)')
xlabel('columns');ylabel('rows');

% % 3D:
figure;
[aa,bb,cc]=meshgrid([1,2,3,5,5,4,3,2,2]);
dd=(aa.*bb.*cc).*(1/3);dd(5:8,4:7,5:8)=nan; % make interesting 3D data
ee=avinterpnan(dd); % default method='linear' interpolation
mesh(squeeze(dd(6,:,:)));title('3D example: data with nans');
xlabel('columns');ylabel('rows');figure;
surf(squeeze(ee(6,:,:)));title('3D example: new data (nans interpolated with method)')
xlabel('columns');ylabel('rows');

% % Changing the interpolation from the default ('linear') to another method (a 2D example)

figure;
[aa,bb,cc]=meshgrid([1,2,3,5,5,4,3,2,2]);
dd=(aa.*bb.*cc).*(1/3);dd(5:8,4:7,5:8)=nan;

method='spline'; % type: help interp1 to see other available interpolation methods.
ee=avinterpnan(dd,method);

mesh(squeeze(dd(6,:,:)));title('3D example: data with nans');
xlabel('columns');ylabel('rows');figure;
surf(squeeze(ee(6,:,:)));title('3D example: new data (nans interpolated with method=''cubic'')')
xlabel('columns');ylabel('rows');

引用

Matt Molteno (2024). avinterpnan(A,method) (https://www.mathworks.com/matlabcentral/fileexchange/59483-avinterpnan-a-method), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2015b
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersInterpolation についてさらに検索
謝辞

ヒントを得たファイル: Inpaint over missing data in 1-D, 2-D, 3-D,... ND arrays, interp1nan, table lookup

ヒントを与えたファイル: meshcompare(varargin)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
バージョン 公開済み リリース ノート
1.1.0.0

Changed the text in the description (made the examples better).

1.0.0.0