简体   繁体   English

如何解决:使用horzcat时发生错误所连接矩阵的维数不一致

[英]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.

相关问题 我的代码运行,有时会出现错误“使用horzcat时出错,所连接的矩阵维数不一致。” - My code runs then sometimes it has error “Error using horzcat Dimensions of matrices being concatenated are not consistent.” 使用CAT的matlab错误,所连接矩阵的维数不一致 - matlab error using CAT, Dimensions of matrices being concatenated are not consistent 使用垂直时发生错误:串联的矩阵尺寸不一致 - Error using vertical: Dimensions of matrices being concatenated are not consistent 我如何处理“使用vertcat的错误连接矩阵的尺寸在Matlab中不一致”? - How do i handle “Error using vertcat Dimensions of matrices being concatenated are not consistent” in Matlab? 使用带有字符的数组时,要级联的矩阵的维数不一致 - Dimensions of matrices being concatenated are not consistent using array with characters bsxfun:所连接矩阵的维数不一致 - bsxfun: Dimensions of matrices being concatenated are not consistent matlab连接的矩阵尺寸不一致 - matlab Dimensions of matrices being concatenated are not consistent Matlab代码崩溃并给出错误:所连接矩阵的维数不一致 - Matlab code crashes and gives error: Dimension of matrices being concatenated are not consistent 在MATLAB中调试错误“被连接的数组的维度不一致” - Debugging the error "Dimensions of arrays being concatenated are not consistent" in MATLAB 在1x6802 double和6802x1 double数据矩阵中,级联矩阵的尺寸不一致 - Dimensions of matrices being concatenated are not consistent in 1x6802 double and 6802x1 double data matrix
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM