Combining 2 matrix of different row numbers but same column numbers.

5 ビュー (過去 30 日間)
Gratitude Kim
Gratitude Kim 2017 年 7 月 27 日
コメント済み: Gratitude Kim 2017 年 7 月 27 日
A = [1 0 0 0 1 0 0 0; 0 1 0 0 0 1 0 0; 0 0 1 0 0 0 1 0; 0 0 0 1 0 0 0 1]
B = [1 1 0 0 0 0 0 0 -2 0 0; 0 1 1 0 0 0 0 0 0 -2 0; 0 0 1 1 0 0 0 0 0 0 -2]
ATotal = [A zeros(4,3)]
Afinal = [ATotal B]
I am having this error. Error using horzcat Dimensions of matrices being concatenated are not consistent.
Error in july6 (line 5) Afinal=[ATotal B]
Appreciate your kind assistance.
  1 件のコメント
Jan
Jan 2017 年 7 月 27 日
I've formatted your code to make it readable. Please use the "{} Code" button by your own in the future.

サインインしてコメントする。

回答 (2 件)

Jan
Jan 2017 年 7 月 27 日
編集済み: Jan 2017 年 7 月 27 日
How coud we help you? You try to concatenate a [4 x 11] and a [3 x 11] matrix horizontally. But the horizontal concatenation requires the same number of rows.
Perhaps you mean the vertical concatenation:
Afinal = [ATotal; B]
But I cannot guess the intention of the code based on the failing code only.
  1 件のコメント
Gratitude Kim
Gratitude Kim 2017 年 7 月 27 日
yaya. I know my mistake. I forgot to place a ; thanks anyway.

サインインしてコメントする。


KL
KL 2017 年 7 月 27 日
Dimensions of ATotal and B are not consistent, look at the number of rows.
Afinal=[ATotal [B; zeros(1,size(B,2))]]

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by