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.
解答:文章来源:https://www.toymoban.com/news/detail-810969.html
% 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,"DisplayName","Filled missing entries")
title("Number of filled missing entries: " + nnz(missingIndices))
hold off
legend
clear missingIndices
任务2:
Look at the generated code. Copy and adapt it to create a vector z
that uses "linear"
interpolation to replace the NaN
values of x
.
解答:
% Fill missing data
[z,missingIndices] = fillmissing(x,"linear");
任务3:
Plot z
with "*"
markers and a solid line. Add this plot to the existing figure.
解答:
hold on
plot(z,"*-")
hold off
笔记:注意示例中画图的方法。文章来源地址https://www.toymoban.com/news/detail-810969.html
到了这里,关于MATLAB Fundamentals>>>Fill Missing Values的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!