How to add to create matrix by combining two columns

46 ビュー (過去 30 日間)
Thallon Pitchure
Thallon Pitchure 2020 年 8 月 29 日
回答済み: Bruno Luong 2020 年 8 月 29 日
Hello! I am trying to do some matrix expansion. I have two columns of data that I have label as h and newCol. They both include 10 rows. My question is how to take these vectors and put them in a single 10x2 matrix. I have tried using newMat = [newCol; h] and the output is a single column with 20 rows. I also tried newMat = [newCol(:); h(:)] and had similar results. I am unsure what I am doing wrong.

回答 (2 件)

Hussein Ammar
Hussein Ammar 2020 年 8 月 29 日
Use horzcat, e.g.,
C= horzcat(A,B)

Bruno Luong
Bruno Luong 2020 年 8 月 29 日
newMat = [newCol, h]


Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by