Enlarge vector by putting average of surrounding numbers in between of every number of original vector

1 次查看(过去 30 天)
How to make a longer vector by adding an additional element between neighboring elements in the original vector. Each new element should equal the average of its neighboring elements. x = [0 2 3 2 1 -1]
  3 个评论

请先登录,再进行评论。

采纳的回答

Birdman
Birdman 2018-1-17
x(3:2:2*numel(x)-1)=x(2:end);
for i=2:2:numel(x)-1
x(i)=(x(i-1)+x(i+1))/2
end

更多回答(1 个)

Stephen23
Stephen23 2018-1-17
编辑:Stephen23 2018-1-17
Without a loop:
>> x = [0 2 3 2 1 -1];
>> y = [x;mean([x(1:end-1);x(2:end)]),0];
>> y = y(1:end-1)
y =
0.00000 1.00000 2.00000 2.50000 3.00000 2.50000 2.00000 1.50000 1.00000 0.00000 -1.00000

标签

尚未输入任何标签。

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by