Average of two elements in a vector that have specific index
Show older comments
Hi all,
I have a vector
where each two elements corresponds to a group, so as a result there are four goups and in each there are two numbers, as shown below in the image:

I want to compute the averge of ith-element of each group and store the answer in a new vector. For example, the averge of the first element from each gorup (the red circles) is 4, as shwon above. The resulting vector should be
in size.
%Define the number of elements in each group
NoElements = 2;
%Define the number of groups
NoGroups = 4;
%Define the vector
A =[1
2
3
4
5
6
7
8];
%perform the averaging
for j = 1:NoElements
A_ave(j) = ?
end
Any help would be appreicted.
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!