How do I create a vector of the average of consecutive elements of another vector (without using a loop)?
40 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Azzi Abdelmalek
2013-10-10
编辑:Azzi Abdelmalek
2013-10-10
A=[2 4 6 8 10]
B=mean([A(1:end-1);A(2:end)])
更多回答(2 个)
Matthew Crema
2013-10-10
One way:
A=[2 4 6 8 10];
foo = conv([1 1], A)/2;
B = foo(2:end-1)
B =
3 5 7 9
-Matt
5 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!