www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/InterpolateMissingDataExample.m

    %% Interpolate Missing Data
% Use interpolation to replace |NaN| values in non-uniformly sampled data.

%%
% Define a vector of non-uniform sample points and evaluate the sine
% function over the points.
x = [-4*pi:0.1:0, 0.1:0.2:4*pi];
A = sin(x); 

%%
% Inject |NaN| values into |A|.
A(A < 0.75 & A > 0.5) = NaN;

%%
% Fill the missing data using linear interpolation, and return the filled
% vector |F| and the logical vector |TF|.  The value 1 (|true)| in entries
% of |TF| corresponds to the values of |F| that were filled.  
[F,TF] = fillmissing(A,'linear','SamplePoints',x);

%%
% Plot the original data and filled data.
plot(x,A,'.', x(TF),F(TF),'o')
xlabel('x');
ylabel('sin(x)')
legend('Original Data','Filled Missing Data')