Q:

Matlab Vectorization using Multiple Columns from an Array

I'm trying to vectorize a bit of Matlab code that requires input from two adjacent members of an array.  Essentially:  
x=1:10;
for i=1:9
    y(i) = x(i)+x(i+1);
end

Is there a way to vectorize this code so that I don't need to use the for loop?

A:

Do I understand this right? Is this what you need?
y = x(1:n-1) + x(2:n);

?

