MATLAB: How to calculate the average between each two adjacent members(rows or columns)

arrayarraysmatrixmatrix array

Hi All
I have an array like
a= [1 2 3 4 5]
and I need the average between two members and add it to a new array
av= [1.5, 2.5, 3.5, 4.5]
which will have one les member obviously

Best Answer

Try this:
>> a= [1 2 3 4 5];
b = (a(1:end-1) + a(2:end))/2
b =
1.5000 2.5000 3.5000 4.5000