Main Content

使用实时编辑器任务清理杂乱数据并定位极值

您可以使用实时编辑器任务序列以交互方式预处理数据,在每个步骤可视化数据。此示例使用五项任务来清理有缺失值和离群值的含噪数据,以便识别局部最小值和最大值。有关实时编辑器任务的详细信息,请参阅将交互式任务添加到实时脚本中

首先,创建并绘制一个由杂乱数据组成的向量,其中包含四个 NaN 值和五个离群值。

x = 1:100;
data = cos(2*pi*0.05*x+2*pi*rand) + 0.5*randn(1,100);
data(20:20:80) = NaN;
data(10:20:90) = [-50 40 30 -45 35];

要绘制杂乱的数据,请打开创建绘图任务。首先在代码块中键入关键字 plot,然后当 Create Plot 出现在菜单中时点击它。选择绘图类型和输入数据以绘制数据。

要查看此任务生成的代码,请点击任务参数区域底部的 Small arrow pointing down 展开任务显示。

Live Task

Figure contains an axes object. The axes object with title x vs. data, xlabel x, ylabel data contains an object of type line. This object represents data.

填充缺失数据

要替换数据中的 NaN 值并可视化结果,请打开清洗缺失数据任务。首先在代码块中键入关键字 missing,然后当 Clean Missing Data 出现在菜单中时点击它。选择输入数据和清洗方法,以自动绘制填充的数据。

要查看此任务生成的代码,请点击任务参数区域底部的 Small arrow pointing down 展开任务显示。

Live Task

Figure contains an axes object. The axes object with title Number of filled missing entries: 4 contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Cleaned data, Filled missing entries.

填充离群值

现在,您可以使用清洗离群数据任务从上一任务的经过清理的数据中删除离群值。在新代码块中键入关键字 outliers,然后点击 Clean Outlier Data 打开任务。选择 cleanedData 作为输入数据。您可以自定义清理和检测离群值的方法,并调整阈值以找到更多或更少的离群值。

要查看此任务生成的代码,请点击任务参数区域底部的 Small arrow pointing down 展开任务显示。

Live Task

Figure contains an axes object. The axes object with title Number of outliers cleaned: 5 contains 5 objects of type line. One or more of the lines displays its values using only markers These objects represent Input data, Cleaned data, Outliers, Filled outliers, Outlier thresholds.

平滑处理数据

接下来,使用平滑处理数据任务来对在上一任务中经过清理的数据进行平滑处理。键入关键字 smooth,并在任务出现时点击它。选择前一任务的输出 cleanedData2 作为输入数据。选择一种平滑方法,并调整平滑因子以实现更多或更少的平滑处理。

要查看此任务生成的代码,请点击任务参数区域底部的 Small arrow pointing down 展开任务显示。

Live Task

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent Input data, Smoothed data.

找到极值

最后,键入关键字 extrema,然后点击 Find Local Extrema。使用 smoothedData 作为输入数据,并更改极值类型,以找到经过清理和平滑处理的数据的局部最大值和局部最小值。您可以调整局部极值参数以找到更多或更少的最大值和最小值。

要查看此任务生成的代码,请点击任务参数区域底部的 Small arrow pointing down 展开任务显示。

Live Task

Figure contains an axes object. The axes object with title Number of extrema: 11 contains 3 objects of type line. One or more of the lines displays its values using only markers These objects represent Input data, Local maxima, Local minima.

另请参阅

实时编辑器任务

函数

相关主题