所以我想连接一个m x n
矩阵来获得1 x mn
矩阵。我想连接的矩阵是从while循环生成的。虽然列数始终为3
,但我无法确定每次迭代会有多少行。此外,每次迭代的行大小可能并不总是相同。
代码在行大小都等于6
的情况下运行,但如果它们不相等,我会收到错误:
使用vertcat时出错连接的矩阵尺寸不一致。
部分代码如下:
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
有人可以告诉我这里我做错了什么。如果有需要,我会进一步澄清。谢谢你们!
答案 0 :(得分:0)
如果B
最终成为行向量,那么您需要更改此内容:
B = [B; reshape(A.',1,[])]; % Does vertical concatenation
到此:
B = [B reshape(A.',1,[])]; % Does horizontal concatenation (note there's no semicolon)
以便从重塑A
获得的每个行向量获取added to the end of the row而不是新行(as the semicolon indicates)。