How to put 2 matrices together to make one matrix?

251 ビュー (過去 30 日間)
Carson Fiscus
Carson Fiscus 2019 年 5 月 1 日
コメント済み: Stephen23 2023 年 4 月 13 日
I'm currently trying to make a 7x2 matrix and a 3x2 matrix into one 10x2 matrix. what I'd like to do is just "stack" the 2 on top of each other.
is there any easy way to do this?
thanks.

回答 (3 件)

James Tursa
James Tursa 2019 年 5 月 1 日
編集済み: James Tursa 2019 年 5 月 1 日
To stack them vertically,
A = your 7x2 matrix
B = your 3x2 matrix
result = [A;B];
If you had two matrices that you wanted to combine side by side (horizontally), you would use a comma instead of a semi-colon. E.g.,
C = a 4x3 matrix
D = a 4x5 matrix
result = [C,D]; % a 4x8 matrix

divya soni
divya soni 2020 年 8 月 6 日
編集済み: divya soni 2020 年 8 月 6 日
X=7×2 matrix;
Y=3×2 matrix;
Z=[X;Y];

maziar
maziar 2023 年 4 月 13 日
Hello Guys. I want to combine a lot of matrices together side by side without putting each of their names ony by one in the code. Is there any loop or other function to do that?
  1 件のコメント
Stephen23
Stephen23 2023 年 4 月 13 日
"I want to combine a lot of matrices together side by side without putting each of their names ony by one in the code."
You forgot to tell us the most important information: how did you get all of those separate variables into the workspace? Hopefully not by writing their names out by hand.... so most likely they were created e.g. when LOADing the data into MATLAB, in which case that is the best place to fix your code:
S = load(...)
Always LOAD into an output variable, and then you can process the fields of S.

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by