add vector to an existing matrix

275 ビュー (過去 30 日間)
Locks
Locks 2013 年 4 月 10 日
hi,
I have the follogin problem: I have a matrix cosisting of 8 columns and 19599 rows and I would first generate a column vector with 19599 elements and add this to the existing matrix. I tired the following:
data9= zeros(size(data8,1),9);
data9(:,1:8) = data8;
where data 8 is the existing matrix with 8 columns and I am intending to create a nineth column which can be fillled.
than I create the clumn vector called moneyness which is a double vecotr
and then I did
data9(i,9) = moneyness;
unfortunately, this gives me the following error message:
Subscripted assignment dimension mismatch.
Error in construct_data (line 36) data9(i,9) = moneyness;
IS there anybody who can help me?

採用された回答

James Tursa
James Tursa 2013 年 4 月 10 日
Did you mean this?
data9(:,9) = moneyness;
Another way to do it:
data9 = [data8 moneyness];
  2 件のコメント
Locks
Locks 2013 年 4 月 10 日
perfect, thanks
Maria-Augusta Miceli
Maria-Augusta Miceli 2021 年 12 月 5 日
Perfect, great!

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

その他の回答 (1 件)

Susan
Susan 2013 年 4 月 10 日
編集済み: Susan 2013 年 4 月 10 日
data9 = zeros(size(data8,1),1);
data9 = [data8,data9];
This will concatenate the variables together, giving you a 19599 x 9 matrix.

カテゴリ

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