【问题标题】:Matrix dimensions must agree矩阵尺寸必须一致
【发布时间】:2012-07-12 10:18:50
【问题描述】:

应用此方法时:

%% When an outlier is considered to be more than three standard deviations away from the mean, use the following syntax to determine the number of outliers in each column of the count matrix:

mu = mean(data)
sigma = std(data)
[n,p] = size(data);
% Create a matrix of mean values by replicating the mu vector for n rows
MeanMat = repmat(mu,n,1);
% Create a matrix of standard deviation values by replicating the sigma vector for n rows
SigmaMat = repmat(sigma,n,1);
% Create a matrix of zeros and ones, where ones indicate the location of outliers
outliers = abs(data - MeanMat) > 3*SigmaMat;
% Calculate the number of outliers in each column
nout = sum(outliers) 
% To remove an entire row of data containing the outlier
data(any(outliers,2),:) = []; %% this line

最后一行从我的数据集中删除了一定数量的观察(行)。然而,我后来在我的程序中遇到了一个问题,因为我手动将观察数(行数)声明为 1000。

%% generate sample data
K = 6;
numObservarations = 1000;
dimensions = 3;

如果我将numObservarations 更改为data,我会收到一个标量输出错误,但是如果我不更改它,由于行数不匹配,我会收到此错误:

??? Error using ==> minus
Matrix dimensions must agree.

Error in ==> datamining at 106
    D(:,k) = sum( ((data -
    repmat(clusters(k,:),numObservarations,1)).^2), 2);

有没有办法设置numObservarations,以便它自动检测data 中的行数并将其输出为一个数字?

【问题讨论】:

    标签: matlab


    【解决方案1】:

    我一定是误会了什么。据我所知,这应该足够了:

    numObservations = size(data, 1);
    

    【讨论】:

      猜你喜欢
      • 2011-12-05
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多