in MATLAB i wish to insert a value half way between every element in the vector
for example
v=[1,3,5,7,9]
i want to get
v=[1,2,3,4,5,6,7,8,9]
is there a quick way to do this?
A very simple, general way to do this is with interpolation, specifically the function INTERP1:
>> v = [1 3 5 7 9]
v =
1 3 5 7 9
>> v = interp1(v,1:0.5:numel(v))
v =
1 2 3 4 5 6 7 8 9
a = [1 3 5 7 9];
b = [2 4 6 8];
c = zeros(9,1);
c(1:2:9) = a; c(2:2:8) = b;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With