Search code examples
matlabvectorextend

Extend vector in Matlab


I have a simple doubt, I want to extend in Matlab a vector:

a = [1 2 3 4 n];

In the following way:

b = [1 1.5 2 2.5 3 3.5 4 ... n];

This means, make a new vector with the double size of the previous one, but the new added values must be the mean of the previous and the next number.

Any idea of a loop to solve this problem?


Solution

  • A possible solution

    b(1:2:2*numel(a)-1)=a
    b(2:2:end) = a(1:end-1)+diff(a)/2