MATLAB Fundamentals>Preprocessing Data>Interpolating Missing Data> (1/4) Fill Missing Values
This code sets up the activity.
x = [0 NaN 7 8 NaN 2 -3 NaN -8]
plot(x,"s-","LineWidth",1.5)
任务1:
Create a vector y
that uses the nearest value to interpolate the NaN
values of x
.
Display the results by making sure Cleaned data
and Fill missing entries
are checked.
解答:
% Fill missing data
[y,missingIndices] = fillmissing(x,"nearest");
% Display results
figure
% Plot cleaned data
plot(y,"SeriesIndex",1,"LineWidth",1.5,"DisplayName","Cleaned data")
hold on
% Plot filled missing entries
plot(find(missingIndices),y(missingIndices),".","MarkerSize",12, ...
"SeriesIndex",2,"DisplayNa