MATLAB Answers

Joe Abraham

Insert values into an array

Asked by Joe Abraham
on 5 Jul 2012

A = [1 3 5 6 7 13]

I want to insert 0 in the 1st cell resulting in

A=[0 1 3 5 6 7 13]

Thanks

  0 Comments

1 Answer

Answer by Walter Roberson
on 5 Jul 2012
 Accepted answer
A = [0 A];  %build new array

Or:

A(2:end+1) = A;  %shift over and zero
A(1) = 0;

  0 Comments


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today