Matlab数据处理之std函数获取数组标准差

您所在的位置:网站首页 matlab数组重排 Matlab数据处理之std函数获取数组标准差

Matlab数据处理之std函数获取数组标准差

2023-03-31 21:52| 来源: 网络整理| 查看: 265

文章目录

展开 std函数基本用法std函数用法介绍实例矩阵列的标准差三维阵列的标准差指定标准差权重沿矩阵行的标准差不含NaN的标准差 4.7 (3)

Matlab中,有一个std函数,可以计算数组的标准差。本文将从std函数基本用法、std函数用法介绍、std函数实例等几个方面入手介绍std函数。其中实例主要包括:矩阵列的标准差、三维阵列的标准差、指定标准差权重、沿矩阵行的标准差、不含NaN的标准差。

Matlab数据处理之std函数获取数组标准差

标准差(Standard Deviation) ,数学术语,是离均差平方的算术平均数(即:方差)的算术平方根,用σ表示。标准差也被称为标准偏差,或者实验标准差,在概率统计中最常使用作为统计分布程度上的测量依据。

std函数帮助文档如下:

>> help std std Standard deviation. For vectors, Y = std(X) returns the standard deviation. For matrices, Y is a row vector containing the standard deviation of each column. For N-D arrays, std operates along the first non-singleton dimension of X. std normalizes Y by (N-1), where N is the sample size. This is the sqrt of an unbiased estimator of the variance of the population from which X is drawn, as long as X consists of independent, identically distributed samples. Y = std(X,1) normalizes by N and produces the square root of the second moment of the sample about its mean. std(X,0) is the same as std(X). Y = std(X,FLAG,DIM) takes the standard deviation along the dimension DIM of X. Pass in FLAG==0 to use the default normalization by N-1, or 1 to use N. std(..., MISSING) specifies how NaN (Not-A-Number) values are treated. The default is 'includenan': 'includenan' - the standard deviation of a vector containing NaN values is also NaN. 'omitnan' - elements of X or W containing NaN values are ignored. If all elements are NaN, the result is NaN. Example: If X = [4 -2 1; 9 5 7] then std(X,0,1) is [3.5355 4.9497 4.2426] and std(X,0,2) is [3.0; 2.0]std函数基本用法S = std(A) S = std(A,w) S = std(A,w,dim) S = std(___,nanflag)std函数用法介绍

S=std(A)返回A元素沿第一个数组维度的标准偏差,该维度的大小不等于1。

如果A是观测向量,那么标准差就是标量。如果A是一个矩阵,其列是随机变量,其行是观察值,那么S是一个行向量,包含对应于每一列的标准偏差。如果A是多维数组,则std(A)沿着大小不等于1的第一个数组维度进行操作,将元素视为向量。此维度的大小变为1,而所有其他维度的大小保持不变。默认情况下,标准偏差标准化为N-1,其中N是观测值的数量。

S=std(A,w)为前面的任何语法指定一个加权方案。当w=0(默认值)时,S由N-1归一化。当w=1时,S通过观察次数归一化N。w也可以是包含非负元素的权重向量。在这种情况下,w的长度必须等于std操作的维度的长度。

S=std(A,w,dim)返回前面任何语法的维度dim的标准偏差。要在指定操作维度时保持默认规范化,请在第二个参数中设置w=0。

S=std(_,nanflag)指定是否在前面任何语法的计算中包含或忽略NaN值。例如,std(A,’includenan’)包括A中的所有NaN值,而std(B,’omitnan’)忽略它们。

实例矩阵列的标准差

创建一个矩阵并计算每列的标准偏差

>> A = [4 -5 1; 2 3 5; -9 1 7]; >> S = std(A) S = 7.0000 4.1633 3.0551三维阵列的标准差

创建三维阵列,并计算沿第一维度的标准偏差

>> A(:,:,1) = [2 4; -2 1]; >> A(:,:,2) = [9 13; -5 7]; >> A(:,:,3) = [4 4; 8 -3]; >> S = std(A) S(:,:,1) = 2.8284 2.1213 S(:,:,2) = 9.8995 4.2426 S(:,:,3) = 2.8284 4.9497Matlab数据处理之std函数获取数组标准差指定标准差权重

创建一个矩阵,并根据权重向量w计算每列的标准偏差。这里你可以理解为把w数组的每一个值作为A矩阵对应每一行的权重值,计算平均值,再计算标准差。

>> A = [1 5; 3 7; -9 2]; >> w = [1 1 0.5]; >> S = std(A,w) S = 4.4900 1.8330沿矩阵行的标准差

创建矩阵并计算每行的标准偏差。

>> A = [6 4 23 -3; 9 -10 4 11; 2 8 -5 1]; >> S = std(A,0,2) S = 11.0303 9.4692 5.3229不含NaN的标准差

创建一个向量并计算其标准偏差,不包括NaN值。

>> A = [1.77 -0.005 3.98 -2.95 NaN 0.34 NaN 0.19]; >> S = std(A,'omitnan') S = 2.2797Matlab数据处理之std函数获取数组标准差

共计3人评分,平均4.7分

到目前为止还没有投票~

很抱歉,这篇文章对您没有用!

让我们改善这篇文章!

告诉我们我们如何改善这篇文章?

原创文章,作者:古哥,转载需经过作者授权同意,并附上原文链接:https://iymark.com/articles/3843.html



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3