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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

add elements to an existing vector

Asked by Locks on 1 May 2013

Hi,

I have a vector where I would like to add 5 NaN at the beginning. When I am doing it for one NaN, it's working fine, but not for five

This code worked fine:

lastDelta = [NaN;delta(1:end-1)];

and creates me a new vector that consists of one NaN and all the element of the existing vector delta except the last one

however, this code here is not working:

lastDelta = [NaN;NaN;NaN;NaN;NaN;delta(1:end-5)];

Has anybode an idea what I am missing?

0 Comments

Locks

Products

No products are associated with this question.

2 Answers

Answer by Lam on 1 May 2013
Accepted answer

You mean adding or replacing?

This works for me:

delta = [1;2;3]
[NaN;NaN;NaN;NaN;NaN;delta(1:end)]

1 Comment

Locks on 1 May 2013

I am looking for a way to create a new vector that contains 5 NaN and then all the elemets from vector delta, except for the last 5, due to the fact that both vectors should have the same length

Lam
Answer by Youssef KHMOU on 1 May 2013

hi, try this :

 R=rand(1,10); % initial vector
 add=NaN*ones(1,5);
 New=[add R];

1 Comment

Locks on 1 May 2013

it's working now, one of the series had just not enough elements, thanks

Youssef  KHMOU

Contact us