[英]How to solve: Error using horzcat Dimensions of matrices being concatenated are not consistent
Everything is fine in the concatenation step. 在连接步骤中一切都很好。 When I am saving these variables (each variable has size 30x180) and I am labeling it in the Labeling step, I got this error, help with this? 当我保存这些变量(每个变量的大小为30x180)并在“标签”步骤中对其进行标签时,出现此错误,对此有帮助吗?
What I want is to add the label number to each row of the feature matrix Class1
. 我想要的是将标签号添加到要素矩阵Class1
每一行。
Error using horzcat Dimensions of matrices being concatenated are not consistent. Error in CONCAT (line 16) dlmwrite(strcat('E:\\Matlab Projects\\FER\\Features\\','.txt'), [Class1 1] , 'delimiter', '\\t','-append','roffset',0, 'precision', 4);
% Concatenation Step
class1 = cat(2,(load(fullfile('.', 'Features', 'ANG1.txt'))), (load(fullfile('.', 'Features', 'ANG11.txt'))));
% Labeling Step
dlmwrite(strcat('E:\Matlab Projects\FER\Features\','.txt'), [Class1 1] , 'delimiter', '\t','-append','roffset',0, 'precision', 4);
Given a matrix Class1
or arbitrary size, adding a 1
at the end of each row is accomplished as follows: 给定矩阵Class1
或任意大小,可以在每行的末尾添加1
,如下所示:
nrows = size(Class1,1);
[Class1 ones(nrows,1)]
The ones
function creates a matrix with ones, of the requested size. ones
函数创建一个带有一个请求大小的矩阵。 Here, we're using the number of rows in Class1
, so that the two matrices have the same number of rows and can be concatenated. 在这里,我们使用Class1
的行数,以便两个矩阵具有相同的行数并且可以串联。
In general, to add an arbitrary number n
, you can do either: 通常,要添加任意数字n
,您可以执行以下任一操作:
[Class1, ones(nrows,1) * n]
or: 要么:
[Class1, zeros(nrows,1) + n]
or: 要么:
[Class1, repmat(n,nrows,1)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.