使用垂直时出错:连接的矩阵的维数不一致

Error using vertical: Dimensions of matrices being concatenated are not consistent

我正在研究多层感知器分类器(在 fisher iris 数据集上,所以是多类分类),我遇到了上面提到的(关于这个问题的标题)错误。我不知道为什么,因为我的矩阵具有相同的行和列。一切似乎都是正确的,但显然有些事情是错误的!

代码:

% Perceptron(Multilayer perceptron)

% coding (+1/-1) of 3 classes
a = [-1 -1 +1]';%'//
b = [-1 +1 -1]';%'//
c = [+1 -1 -1]';%'//
% define training inputs
rand_ind = randperm(50);
trainSeto = meas(rand_ind(1:35),:);
trainVers = meas(50 + rand_ind(1:35),:);
trainVirg = meas(100 + rand_ind(1:35),:);
trainInp = [trainSeto trainVers trainVirg];
% define targets
T = [repmat(a,1,length(trainSeto)) repmat(b,1,length(trainVers))
repmat(c,1,length(trainVirg))];

那么,我的代码有什么问题,我该如何解决?

谁能帮帮我?

meas=rand(200,4);
a = [-1 -1 +1]';%'//
b = [-1 +1 -1]';%'//
c = [+1 -1 -1]';%'//
% define training inputs
rand_ind = randperm(50);
trainSeto = meas(rand_ind(1:35),:);
trainVers = meas(50 + rand_ind(1:35),:);
trainVirg = meas(100 + rand_ind(1:35),:);
trainInp = [trainSeto trainVers trainVirg];
% define targets
tmp1 = repmat(a,1,length(trainSeto));
tmp2 = repmat(b,1,length(trainVers));
tmp3 = repmat(c,1,length(trainVirg));
T = [tmp1 tmp2 tmp3];
clear tmp1 tmp2 tmp3 %// Used for cleaning the temporaries

我认为 MATLAB 在处理串联运算符 ([]) 中的三个 repmat 调用时遇到困难。即我认为它首先尝试 repmat,但卡在如何以及何时 repmat 第二个。如果您定义临时变量,它工作正常。如果您不希望临时文件弄乱您的工作区,您可以使用 clear 调用。