Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab初学者中值、模态和binning_Matlab_Math - Fatal编程技术网

Matlab初学者中值、模态和binning

Matlab初学者中值、模态和binning,matlab,math,Matlab,Math,我是一名MATLAB初学者,我正在努力完成这项任务。有人能引导我通过它吗 考虑以下给出的数据: x = [ 1 , 48 , 81 , 2 , 10 , 25 , ,14 , 18 , 53 , 41, 56, 89,0, 1000, , ... 34, 47, 455, 21, , 22, 100 ]; 加载数据后,查看是否可以找到: 异常值或 数据文件中缺少数据 使用中值分块、平均分块和分块边界,使用中值、模式和噪声数据纠正缺失值 这还不错。首先,看看数据的分布情况。您可以看到

我是一名MATLAB初学者,我正在努力完成这项任务。有人能引导我通过它吗

考虑以下给出的数据:

x = [ 1 , 48 , 81 , 2 , 10 , 25 , ,14 , 18 , 53 , 41, 56, 89,0, 1000, , ...
      34, 47, 455, 21, , 22, 100 ];
加载数据后,查看是否可以找到:

  • 异常值或
  • 数据文件中缺少数据

  • 使用中值分块、平均分块和分块边界,使用中值、模式和噪声数据纠正缺失值

    这还不错。首先,看看数据的分布情况。您可以看到,您的大多数数据都有两位数。离群值是指具有一位数的离群值,或者比两位数大得多的离群值。请注意,这完全是主观的,因此其他人可能会告诉您,单个数字也是您数据的一部分。此外,缺少的数据是逗号之间的空格数字。让我们编写一些MATLAB代码,并将其更改为
    NaN
    (或非数字),因为如果您尝试将此代码直接复制并粘贴到MATLAB中,将产生语法错误,因为如果您以这种方式显式定义数字,您必须确保所有数字都存在

    要执行此操作,请使用,以便此字符串中有逗号、空格,然后是另一个逗号的任何部分,在两者之间放置一个
    NaN
    。为此,我们首先需要将该语句作为字符串。然后,我们使用
    eval
    将该字符串转换为实际的MATLAB语句:

    x = '[ 1 , 48 , 81 , 2 , 10 , 25 , ,14 , 18 , 53 , 41, 56, 89,0, 1000, , 34, 47, 455, 21, , 22, 100 ];'
    y = eval(regexprep(x, ', ,', ', NaN, '));
    
    如果我们显示这些数据,我们会得到:

    y =
    
    Columns 1 through 6
    
           1          48          81           2          10          25
    
    Columns 7 through 12
    
         NaN          14          18          53          41          56
    
    Columns 13 through 18
    
          89           0        1000         NaN          34          47
    
    Columns 19 through 23
    
         455          21         NaN          22         100
    
    因此,为了回答我们的第一个问题,任何缺失的值都表示为
    NaN
    ,大于两位数的数字都是异常值


    对于下一个问题,我们只需提取缺失的值,计算未缺失值的平均值和中值,并用平均值和中值填充
    NaN
    值。对于bin边界,这与在缺少的值的左侧(或右侧…取决于您的定义,但让我们使用左侧)使用值并进行填充是一样的。因此:

    yMissing = isnan(y); %// Which values are missing?
    y_noNaN = y(~yMissing); %// Extract the non-missing values
    meanY = mean(y_noNaN); %// Get the mean
    medianY = median(y_noNaN); %// Get the median
    
    %// Output - Fill in missing values with median
    yMedian = y;
    yMedian(yMissing) = medianY;
    %// Same for mean
    yMean = y;
    yMean(yMissing) = meanY;
    %// Bin boundaries
    yBinBound = y;
    yBinBound(yMissing) = y(find(yMissing)-1);
    
    非缺失值数据的平均值和中值为:

    meanY =
    
    105.8500
    
    medianY =
    
    37.5000
    
    除了缺少值的原始数据外,这些数据的输出如下所示:

    format bank; %// Do this to show just the first two decimal places for compact output
    format compact;
    
    y =
    Columns 1 through 5
             1          48          81           2          10
    Columns 6 through 10
            25         NaN          14          18          53
    Columns 11 through 15
            41          56          89           0        1000
    Columns 16 through 20
           NaN          34          47         455          21
    Columns 21 through 23
           NaN          22         100
    
    yMean =
    Columns 1 through 5
            1.00         48.00         81.00          2.00         10.00
    Columns 6 through 10
           25.00        105.85         14.00         18.00         53.00
    Columns 11 through 15
           41.00         56.00         89.00             0       1000.00
    Columns 16 through 20
          105.85         34.00         47.00        455.00         21.00
    Columns 21 through 23
          105.85         22.00        100.00
    
    yMedian =
    Columns 1 through 5
            1.00         48.00         81.00          2.00         10.00
    Columns 6 through 10
           25.00         37.50         14.00         18.00         53.00
    Columns 11 through 15
           41.00         56.00         89.00             0       1000.00
    Columns 16 through 20
           37.50         34.00         47.00        455.00         21.00
    Columns 21 through 23
           37.50         22.00        100.00
    
    yBinBound =
    Columns 1 through 5
            1.00         48.00         81.00          2.00         10.00
    Columns 6 through 10
           25.00         25.00         14.00         18.00         53.00
    Columns 11 through 15
           41.00         56.00         89.00             0       1000.00
    Columns 16 through 20
         1000.00         34.00         47.00        455.00         21.00
    Columns 21 through 23
           21.00         22.00        100.00
    


    如果您查看每个输出值,这将根据问题用平均值、中位数和垃圾箱边界填充我们的数据。

    非常感谢。这真的很有帮助。拇指up@user3908734-谢谢!:)欢迎来到StackOverflow!