简体   繁体   English

我如何处理“使用vertcat的错误连接矩阵的尺寸在Matlab中不一致”?

[英]How do i handle “Error using vertcat Dimensions of matrices being concatenated are not consistent” in Matlab?

So I want to concatenate an mxn matrix to obtain a 1 x mn matrix. 所以我想连接mxn矩阵以获得1 x mn矩阵。 The matrix I want to concatenate are generated from a while loop. 我想连接的矩阵是从while循环生成的。 Although the number of columns will always be 3 , I however cannot tell how many rows there will be for each iteration. 虽然列数总是3 ,但我无法确定每次迭代会有多少行。 Also, the row sizes for each iteration may not always be the same. 此外,每次迭代的行大小可能并不总是相同。

The code runs in cases where the row sizes were all equal to 6 , but in cases where they aren't equal I get an error: 代码在行大小都等于6情况下运行,但是在它们不相等的情况下我得到一个错误:

Error using vertcat Dimensions of matrices being concatenated are not consistent. 使用vertcat时出错连接矩阵的维数不一致。

parts of the code are as follows: 部分代码如下:

A = [];
B = [];
searchArea = 2;

for ii = 1: numel(velocity)
    Do ....
    while area(ii,:) < searchArea
        Do ....
        % COLLATE vectors for A
        A = [A; [Ax(ii), Ay(ii), Az(ii)]];
        Do ...
    end
    %# Copy the A into new variable (B) and Reshape into row vector so as to associate each row to its corresponding velocity
    B = [B; reshape(A.',1,[])];
    A = [];
end

Could someone please advice me on what I am doing wrong here. 有人可以告诉我这里我做错了什么。 I would clarify further if there be need. 如果有需要,我会进一步澄清。 Thanks guys! 多谢你们!

If it's your intent that B ends up being a row vector, then you need to change this: 如果你的意图是B最终成为行向量,那么你需要改变这个:

B = [B; reshape(A.',1,[])];  % Does vertical concatenation

to this: 对此:

B = [B reshape(A.',1,[])];  % Does horizontal concatenation (note there's no semicolon)

so that each row vector gotten from reshaping A gets added to the end of the row instead of as a new row ( as the semicolon indicates ). 这样从重新整形A得到的每一行向量都会被添加到行的末尾,而不是作为一个新行( 如分号所示 )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用CAT的matlab错误,所连接矩阵的维数不一致 - matlab error using CAT, Dimensions of matrices being concatenated are not consistent 如何解决:使用horzcat时发生错误所连接矩阵的维数不一致 - How to solve: Error using horzcat Dimensions of matrices being concatenated are not consistent matlab连接的矩阵尺寸不一致 - matlab Dimensions of matrices being concatenated are not consistent 使用垂直时发生错误:串联的矩阵尺寸不一致 - Error using vertical: Dimensions of matrices being concatenated are not consistent 八度到Matlab,使用==&gt; vertcat出错,CAT参数尺寸不一致 - Octave to Matlab, Error using ==> vertcat, CAT arguments dimensions are not consistent 使用带有字符的数组时,要级联的矩阵的维数不一致 - Dimensions of matrices being concatenated are not consistent using array with characters 我的代码运行,有时会出现错误“使用horzcat时出错,所连接的矩阵维数不一致。” - My code runs then sometimes it has error “Error using horzcat Dimensions of matrices being concatenated are not consistent.” bsxfun:所连接矩阵的维数不一致 - bsxfun: 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
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM