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.
다운로드 수: 106
업데이트 날짜: 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 CenterMATLAB Answers에서 Interpolation에 대해 자세히 알아보기

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