Average of every n elements of two separate vector
Show older comments
I have two different vectors A and B (each has 1000 numbers). Each number of A has a specific value in B (A(i,1)=B(i,1)). Some values of A are repeated in 1000 numbers. I want to make an average of every 10 elements in vector A and also find the average of vector B as well, for example:
A=[4 3 1 0 2 3 5 6]
B=[1 3 2 1 0 2 5 6]
I want to make an average every two elements of A, 0-2, 2-4, 4-6 and then find the average values of B .
Get something like:
A(new)=[1 3.33 5.5] ..........1=(0+1+2)/3 ,,,, 3.33=(3+3+4)/3,,,,,,5.5=(5+6)/2 >>>from vector A
B(new)=[1 2 5.5] ............ 1=(1+2+0)/3 ,,,,, 2=(3+2+1)/3 ,,,,,, 5.5=(5+6)/2 >>>>> from vector B
Thank you
1 Comment
Image Analyst
on 11 Nov 2015
Well obviously A(i) does not equal B(i) because A(1) = 4 which is not equal to B(1) which is 1, and so on. So I'm not sure what that statement means.
Another question, are all the numbers integers? Or can you have numbers like 0.123 and 4.835?
When you say "average every two elements of A, 0-2, 2-4, 4-6" do you mean elements (indexes) of A, or values of A? Because, if you're talking about integers, 0,1,2 is 3 numbers, as is 2,3,4, not two numbers like you said. Or if A can be floating point numbers and you're talking about averaging all values in the continuous range 0 to 2, then you might have, say 5 numbers in that range, like 0.1,0.3, 1.3, 1.5, and 1.9, especially if A is 1000 elements long, and not just two numbers. So do you want to average all elements in that range regardless of where they appear and if they're next to each other or not?
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!