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

2 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2013-11-23
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

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2013-11-13
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?

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by