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

meanvector

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

Best Answer

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?