马氏距离在MATLAB中的代码,用代码表示公式.公式如图.i:第几列 k:层数 L:列数 D:两样本之间的距离 x:变量

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/04 14:26:40
马氏距离在MATLAB中的代码,用代码表示公式.公式如图.i:第几列 k:层数 L:列数 D:两样本之间的距离 x:变量

马氏距离在MATLAB中的代码,用代码表示公式.公式如图.i:第几列 k:层数 L:列数 D:两样本之间的距离 x:变量
马氏距离在MATLAB中的代码,用代码表示公式.公式如图.
i:第几列 k:层数 L:列数 D:两样本之间的距离 x:变量

马氏距离在MATLAB中的代码,用代码表示公式.公式如图.i:第几列 k:层数 L:列数 D:两样本之间的距离 x:变量
function d = mahalanobis(X, Mu, C)
  %MAHALANOBIS Mahalanobis distance.
  % D = MAHALANOBIS(X, MU, C) returns the Mahalanobis distance between
  % the length p vectors X and MU given the p by p covariance matrix
  % C. If omitted, it is assumed that C is the identity matrix(单位矩阵/恒等矩阵)
  % EYE(p). If either X or MU is an n by p matrix, D will be returned
  % as an n by g matrix where n is the number of rows in X and g is
  % the number of rows in MU where each entry i, j corresponds to the
  % mahalanobis distance between row i of X and row j of MU. If MU is
  % simply 0, it is treated as the origin from which Mahalanobis
  % distance to X is calculated. C must be a positive, definite,
  % symmetric matrix.
  %
  % The Mahalanobis distance between vectors X(i,:) and MU(j,:) is
  % defined as:
  %
  % D(i,j) = ((X(i,:) - MU(j,:))'*INV(C)*(X(i,:) - MU(j,:))).^(1/2)
  % Copyright (c) 1999 Michael Kiefte.
  % $Log$
  error(nargchk(2, 3, nargin))
  if isempty(X) | ~isa(X, 'double') | ~isreal(X) | ...
  any(any(isnan(X) | isinf(X)))
  error(['X must be a vector or matrix of real, finite numeric' ...
  ' doubles.'])
  elseif length(X) == prod(size(X))
  X = X(:)';
  elseif ndims(X) ~= 2
  error('If X is a matrix, it must be a 2-d array.')
  end
  [n p] = size(X);
  if isempty(Mu) | ~isa(Mu, 'double') | ~isreal(Mu) | ...
  any(any(isnan(Mu) | isinf(Mu)))
  error(['Mu must be a vector or matrix of real, finite numeric' ...
  ' doubles.'])
  elseif length(Mu) == prod(size(Mu))
  Mu = Mu(:)';
  elseif ndims(Mu) ~= 2
  error('If MU is a matrix, it must be a 2-d array.')
  end
  if length(Mu) == 1 & Mu == 0
  Mu = zeros(1, p);
  elseif size(Mu, 2) ~= p
  error('Number of features in MU and X must be the same.')
  end
  g = size(Mu, 1);
  if ~isempty(C)
  if ~isa(C, 'double') | ~isreal(C) | ndims(C) ~= 2 | ...
  any(any(isnan(C) | isinf(C)))
  error('C must be a matrix of real, finite numeric doubles.')
  elseif any(size(C) ~= p)
  error(['Number of rows and columns in C must match number of' ...
  ' features in X and MU.'])
  end
  try
  S = inv(chol(C));
  catch
  error(['Covariance matrix C must be positive, definite,' ...
  ' symmetric.'])
  end
  Xs = X*S;
  Ms = Mu*S;
  else
  Xs = X;
  Ms = Mu;
  end
  d = sqrt(repmat(sum(Xs.^2, 2), 1, g) - 2*Xs*Ms' + ...
  repmat(sum(Ms'.^2), n, 1));

马氏距离在MATLAB中的代码,用代码表示公式.公式如图.i:第几列 k:层数 L:列数 D:两样本之间的距离 x:变量 代码SIC是什么东西?财务管理研究报告中要填写的代码SIC是什么东西,谁有这个的代码表之类的? 用matlab解方程求matlab代码. ..matlab仿真特殊边界电场分布..用超松弛迭代法在matlab仿真特殊边界电场分布.求matlab代码. 求小波分析在数据检测方面的matlab代码,比如给您一组数据,利用小波分析来找出其中的异常值.给您一组数据,能够找出其中的异常值,该数据是一维的.但是如果您能够给出处理多维数据的源代 用matlab编有 这样一段代码 DSP中的梳状滤波器的应用(matlab实现)在matlab中怎么用它对一个声音加回声,一次,三次,无限次.给代码再加分 在ascll编码表中.字母A的ascll代码的十进制值是65.则字母B的ascll代码的十进制值是多少. 已知多个点之间的距离 若固定其中一个点的位置 怎么用matlab画出各个点的分布有matlab 代码最好哦, 求matlab代码!急,请把下面式子用matlab代码写出来 小白求matlab代码我现在有一些在坐标系里的点,假设有十个,坐标都已知,然后我想得到由这些点的连线构成的图的邻接矩阵.就是用矩阵表示两两之间的距离. 自行车码表怎么用 已知各个点的坐标(很多点),怎么用matlab去寻找某一点的距离最近的点并计算出距离?最好给点代码. 欧氏距离怎么求?用matlab, matlab fmincon函数中的迭代初值怎么确定 matlab求不定积分代码 ||在matlab中的意思 matlab遗传算法求函数最小值问题!我要用我的目标函数去替换 代码2.txt 中的目标函数,该修改代码2中的哪些地方,或者是帮我修改好发给我,我的目标函数在这里!