查看: 2433  |  回复: 3
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

niexianling

铜虫 (初入文坛)

[求助] matlab中std2函数计算矩阵的标准差时,分母是除以了n-1还是n?

matlab中std2函数计算矩阵的标准差时,分母是除以了n-1还是n?
这是如下代码
function s = std2(a)
%STD2 Standard deviation of matrix elements.
%   B = STD2(A) computes the standard deviation of the values in
%   A.
%
%   Class Support
%   -------------
%   A can be numeric or logical. B is a scalar of class double.
%
%   Example
%   -------
%       I = imread('liftingbody.png');
%       val = std2(I)
%
%   See also CORR2, MEAN2, MEAN, STD.

%   Copyright 1992-2010 The MathWorks, Inc.
%   $Revision: 5.19.4.6 $  $Date: 2010/09/13 16:14:04 $

% validate that our input is valid for the IMHIST optimization
fast_data_type = isa(a,'logical') || isa(a,'int8') || isa(a,'uint8') || ...
    isa(a,'uint16') || isa(a,'int16');

% only use IMHIST for images of sufficient size
big_enough = numel(a) > 300000;

if fast_data_type && isequal(ndims(a),2) && ~issparse(a) && big_enough
   
    % compute histogram
    if islogical(a)
        num_bins = 2;
    else
        data_type = class(a);
        num_bins = double(intmax(data_type)) - double(intmin(data_type)) + 1;
    end
    [bin_counts bin_values] = imhist(a, num_bins);

    % compute standard deviation
    total_pixels = numel(a);
   
    sum_of_pixels = sum(bin_counts .* bin_values);
    mean_pixel = sum_of_pixels / total_pixels;
   
    bin_value_offsets      = bin_values - mean_pixel;
    bin_value_offsets_sqrd = bin_value_offsets .^ 2;
   
    offset_summation = sum( bin_counts .* bin_value_offsets_sqrd);
    s = sqrt(offset_summation / total_pixels);
   
else
   
    % use simple implementation
    if ~isa(a,'double')
        a = double(a);
    end
    s = std(a();
   
end
回复此楼
do
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

niexianling

铜虫 (初入文坛)

引用回帖:
2楼: Originally posted by 月只蓝 at 2013-06-27 10:34:09
默认的是N-1吧,以下是MATLAB 帮助文档的说明:
STD Standard deviation.
    For vectors, Y = STD(X) returns the standard deviation.  For matrices,
    Y is a row vector containing the standard devi ...

我想知道的是std2函数
do
3楼2013-06-27 11:00:36
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 4 个回答

月只蓝

主管区长 (职业作家)

【答案】应助回帖

★
感谢参与,应助指数 +1
csgt0: 金币+1, 谢谢 2013-06-28 11:32:57
默认的是N-1吧,以下是MATLAB 帮助文档的说明:
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.
MATLAB、MS小问题、普通问题请发帖求助!时间精力有限,恕不接受无偿私信求助。
2楼2013-06-27 10:34:09
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

somomo91

专家顾问 (职业作家)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
niexianling: 金币+30, ★有帮助, 谢谢,我知道了 2013-06-27 20:49:12
csgt0: 金币+1, 谢谢 2013-06-28 11:33:11
引用回帖:
3楼: Originally posted by niexianling at 2013-06-27 11:00:36
我想知道的是std2函数...

遇到过这个问题
matlab 的人回答过 :
std2 调用的是 std 的算法,也就是说,它用的是默认的 (N-1), 除非把 std 里面的参数 FLAG==0 ,变成 FLAG==1
4楼2013-06-27 14:43:54
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[教师之家] 课题组会帮你通过考核么? +3 好运来~9527 2026-10-10 6/300 2026-10-12 14:55 by 简单化xn
[有机交流] OpenAI又攻克数学难题了,离AI做有机合成还有多远? +4 wangyl_123 2026-10-10 7/350 2026-10-12 14:47 by chuans0923
[公派出国] 售一区SCI文章T0P,我:8O.551.O54,科目全,可十急 +5 qR2AdCWTVtkw 2026-10-09 9/450 2026-10-11 22:34 by XQNyDCa1Tk5n
[找工作] 售SCI一区T0P文章,我:8.O55.1.O.54,科目全,可十急 +5 qR2AdCWTVtkw 2026-10-09 8/400 2026-10-11 22:26 by XQNyDCa1Tk5n
[公派出国] 售SCI一区文章,我:8O5.5.1.O5.4,科目全,可伽急 +5 qR2AdCWTVtkw 2026-10-09 10/500 2026-10-11 22:26 by XQNyDCa1Tk5n
[考博] 售SCI一区T0P文章,我:8.O55.1.O.54,科目全,可十急 +5 qR2AdCWTVtkw 2026-10-09 9/450 2026-10-11 22:15 by XQNyDCa1Tk5n
[考博] 售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急 +3 qR2AdCWTVtkw 2026-10-09 7/350 2026-10-11 22:11 by XQNyDCa1Tk5n
[教师之家] 售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急 (EPI+-1)(金币-50) +5 qR2AdCWTVtkw 2026-10-09 10/500 2026-10-11 22:06 by XQNyDCa1Tk5n
[基金申请] 售SCI一区T0P文章,我:8.O.55.1.O54,科目全,可伽急 +5 qR2AdCWTVtkw 2026-10-09 9/450 2026-10-11 22:06 by XQNyDCa1Tk5n
[教师之家] 售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急 (EPI+-1)(金币-50) +5 qR2AdCWTVtkw 2026-10-09 10/500 2026-10-11 14:25 by VOMexwnDzOFZ
[教师之家] 售SCI文章,我:8O.5.5.1O.54,科目全,可十急 (EPI+-1)(金币-50) +4 qR2AdCWTVtkw 2026-10-09 7/350 2026-10-11 14:05 by VOMexwnDzOFZ
[考研] 售SCI文章,我:8O.5.5.1O.54,科目全,可十急 +5 qR2AdCWTVtkw 2026-10-09 8/400 2026-10-11 13:51 by VOMexwnDzOFZ
[硕博家园] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +5 qR2AdCWTVtkw 2026-10-09 8/400 2026-10-11 13:45 by VOMexwnDzOFZ
[找工作] 售SCI一区T0P文章,我:8O.55.1.O.5.4,科目齐全,可+急 +3 qR2AdCWTVtkw 2026-10-09 7/350 2026-10-11 10:54 by VOMexwnDzOFZ
[找工作] 售SCI一区T0P文章,我:8O.55.1.O.5.4,科目齐全,可+急 +4 qR2AdCWTVtkw 2026-10-09 7/350 2026-10-11 10:34 by VOMexwnDzOFZ
[考博] 招收博士生一名 +3 mandolin 2026-10-10 3/150 2026-10-11 10:21 by 不是山谷!
[公派出国] 售SCI一区T0P文章,我:8O.55.1.O.54,科目全,可伽急 +4 qR2AdCWTVtkw 2026-10-09 4/200 2026-10-11 03:14 by M0zrYVSAnxpE
[有机交流] 各位大佬,路线设计求助 +6 zapen 2026-10-08 8/400 2026-10-10 15:59 by zapen
[基金申请] 入职后第一次管课题组的专利缴费,对账才发现官费比别人多掏了一倍 +5 13108017953 2026-10-08 5/250 2026-10-10 11:15 by wdwd123
[有机交流] 我应该选哪条合成路线让实验成功率高一些? +5 jing816y 2026-10-08 9/450 2026-10-10 09:05 by zapen
信息提示
请填处理意见