How to work out the mean for a number of vectors.

2 views (last 30 days)
Hello my fellow companions, hope you are having a fine day. I am trying to work out the mean for a number of vectors (I have like 6 vectors, but would be useful for a generic formula to work out for different ones) , an easier way of doing it. A = [2; 3 ; 4 ; 5] B = [2; 4 ; 5 ; 6] C = [1; 5 ; 6 ;7] D = [4; 7; 8; 2] E = [4; 6; 8; 4] F = [4; 6; 2; 2]
The way I do it is to create an array to add all the vectors G= (A+B+C+D+E+F)/3
  1 Comment
Image Analyst
Image Analyst on 23 Nov 2013
Here is what Shani asked, so that it will still be here when she deletes this question:
Hello my fellow companions, hope you are having a fine day. I am trying to work out the mean for a number of vectors (I have like 6 vectors, but would be useful for a generic formula to work out for different ones) , an easier way of doing it. A = [2; 3 ; 4 ; 5] B = [2; 4 ; 5 ; 6] C = [1; 5 ; 6 ;7] D = [4; 7; 8; 2] E = [4; 6; 8; 4] F = [4; 6; 2; 2]
The way I do it is to create an array to add all the vectors G= (A+B+C+D+E+F)/3

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 13 Nov 2013
That looks really really easy to me. Just a few characters in one line of code - I don't think it can be made much easier than that. Even if you did use another way, you'd still have to list the vectors ,and all you've added are plus signs, parentheses and a divide symbol. I don't think it can be made any simpler.
You could do it with the mean() function but that would involve stuffing the vectors into a 2D array and then getting the means along the rows, and that would be way more complicated than what you are doing. I'd stick with your method, unless the number of vectors is unknown, like you have a function where any unknown number of vectors might be passed in via the varargin cell array.
I don't know what "for different ones" means. Different vectors ? Or different numbers of vectors? What exactly does the "ones" in "for different ones" refer to?

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!