add elements to an existing vector

조회 수: 2 (최근 30일)
Locks
Locks 2013년 5월 1일
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?

채택된 답변

Lam
Lam 2013년 5월 1일
You mean adding or replacing?
This works for me:
delta = [1;2;3]
[NaN;NaN;NaN;NaN;NaN;delta(1:end)]
  댓글 수: 1
Locks
Locks 2013년 5월 1일
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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Youssef  Khmou
Youssef Khmou 2013년 5월 1일
hi, try this :
R=rand(1,10); % initial vector
add=NaN*ones(1,5);
New=[add R];
  댓글 수: 1
Locks
Locks 2013년 5월 1일
it's working now, one of the series had just not enough elements, thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by