【问题标题】:MATLAB The function isnan is undefined for input arguments of type 'dataset'MATLAB 对于“数据集”类型的输入参数,函数 isnan 未定义
【发布时间】:2017-03-12 00:19:47
【问题描述】:

我有一个有点大 (48000*53) 的数据集,我正在尝试找到它上面的多元异常值。 但是,每次我尝试诸如 trimmean()、leverage() 之类的函数时,我都会遇到同样的错误。 我的数据集应该没有 NaN 值,但我仍然尝试运行代码 D(find(sum(isnan(D),2)==0),:);D(any(isnan(D),2), :)=[]; 但我得到了同样的错误....

【问题讨论】:

    标签: matlab dataset nan


    【解决方案1】:

    以下示例从数据集中删除所有包含 NaN 元素的行。

    示例基于以下帖子:Matlab. Replace missed values with an avg

    • 将数据集转换为元胞数组。
    • 查找元胞数组中 NaN 元素的所有索引。
    • 查找包含 NaN 元素的行的索引。
    • 在元胞数组中只保留没有 NaN 元素的行。
    • 将元胞数组转换回数据集。

    检查以下代码示例:

    %Create dataset for the example.
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    VarName1 = [4; NaN; 6; 7; 6; 6; 6; 5; 5; 6; 6];
    VarName2 = [2; 2; 2; 3; 3; 2; NaN; 2; 2; NaN; 3];
    VarName3 = {'aa'; 'aa'; 'aa'; 'bbb'; 'bbb'; 'ccc'; 'ccc'; 'ccc'; 'ccc'; 'dddd'; 'dddd'};
    D = dataset(VarName1, VarName2, VarName3);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %Convert dataset to cell array.
    C = dataset2cell(D);
    
    %Find all indexes of NaN elements (use anonymous function).
    nanIdx = cellfun(@(x)(any(isnan(x))), C);
    
    %Find indexes of rows with NaN elements
    nanRows = any(nanIdx,2);
    
    %Keep only rows without NaN elements.
    C = C(~nanRows, :);
    
    D = cell2dataset(C);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-12
      相关资源
      最近更新 更多