center.m
来自「不完全数据分析MATLAB程序(部分信息重建):最小均方估计、协方差矩阵、缺失值」· M 代码 · 共 29 行
M
29 行
function [xc, xm] = center(x)%CENTER Centers data by subtraction of the mean.%% [XC, XM] = CENTER(X) centers the data in X by subtraction of the% mean XM. If X contains NaNs, indicating missing values, the mean% of X is computed from the available data.%% See also NANMEAN, MEAN. error(nargchk(1,1,nargin)) % check number of input arguments if ndims(x) > 2, error('X must be vector or 2-D array.'); end % if x is a vector, make sure it is a row vector if length(x)==prod(size(x)) x = x(:); end [m,n] = size(x); % get mean of x if any(any(isnan(x))) % there are missing values in x xm = nanmean(x); else % no missing values xm = mean(x); end % remove mean xc = x - repmat(xm, m, 1);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?