MATLAB: How to create a vector of the average of consecutive elements of another vector (without using a loop)

vector

Say, I have a vector A=[2 4 6 8 10]. Is there any way I can create a vector of the average of consecutive elements of A, i.e. B=[3 5 7 9] without using a loop? Is there any matlab function to do that? Thanks in advance.

Best Answer

A=[2 4 6 8 10]
B=mean([A(1:end-1);A(2:end)])