簡體   English   中英

我如何處理“使用vertcat的錯誤連接矩陣的尺寸在Matlab中不一致”?

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

所以我想連接mxn矩陣以獲得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

有人可以告訴我這里我做錯了什么。 如果有需要,我會進一步澄清。 多謝你們!

如果你的意圖是B最終成為行向量,那么你需要改變這個:

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

對此:

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

這樣從重新整形A得到的每一行向量都會被添加到行的末尾,而不是作為一個新行( 如分號所示 )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM