add column of data to array in Matlab

65 ビュー (過去 30 日間)
Kieran Craddock
Kieran Craddock 2017 年 10 月 23 日
編集済み: Cam Salzberger 2017 年 10 月 23 日
Hi my algorithm I have created produces outputs as such:
1 x 45 column vector
How can I then add another 1 x 45 column vector of data to this previous one to make a 2x45, 3x45 etc?

採用された回答

Cam Salzberger
Cam Salzberger 2017 年 10 月 23 日
編集済み: Cam Salzberger 2017 年 10 月 23 日
Hello Kieran,
In MATLAB, we use row x column notation. So a column vector with 45 elements would be 45 x 1.
Use [], horzcat, or just cat to do the concatenation.
a = rand(45, 1);
b = rand(45, 1);
c = [a b];
c = horzcat(a, b);
c = cat(2, a, b);
Note that if you're building an array through concatenation in a loop, then you're probably doing something inefficiently. You can preallocate the matrix, and then compute one row at a time instead.
-Cam

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by