Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

add vector to an existing matrix

Asked by Locks

Locks

on 10 Apr 2013
Accepted Answer by James Tursa

James Tursa

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?

0 Comments

Locks

Locks

Products

No products are associated with this question.

2 Answers

Answer by James Tursa

James Tursa

on 10 Apr 2013
Accepted answer

Did you mean this?

data9(:,9) = moneyness;

Another way to do it:

data9 = [data8 moneyness];

1 Comment

Locks

Locks

on 10 Apr 2013

perfect, thanks

James Tursa

James Tursa

Answer by Susan

Susan

on 10 Apr 2013
Edited by Susan

Susan

on 10 Apr 2013
data9 = zeros(size(data8,1),1);
data9 = [data8,data9];

This will concatenate the variables together, giving you a 19599 x 9 matrix.

0 Comments

Susan

Susan

Contact us