Vous suivez désormais cette soumission
- Les mises à jour seront visibles dans votre flux de contenu suivi
- Selon vos préférences en matière de communication il est possible que vous receviez des e-mails
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');
Citation pour cette source
Matt Molteno (2026). avinterpnan(A,method) (https://fr.mathworks.com/matlabcentral/fileexchange/59483-avinterpnan-a-method), MATLAB Central File Exchange. Extrait(e) le .
Remerciements
Inspiré par : Inpaint over missing data in 1-D, 2-D, 3-D,... ND arrays, interp1nan, table lookup
A inspiré : meshcompare(varargin)
Informations générales
- Version 1.1.0.0 (5,29 ko)
Compatibilité avec les versions de MATLAB
- Compatible avec toutes les versions
Plateformes compatibles
- Windows
- macOS
- Linux
| Version | Publié le | Notes de version | Action |
|---|---|---|---|
| 1.1.0.0 | Changed the text in the description (made the examples better). |
||
| 1.0.0.0 |
