finding the a average of matrix any better way

1 次查看(过去 30 天)
a=[2 4 5;3 2 1;2 3 8;4 1 9];
average=sum(sum(a))/numel(a)
Any better way to do this..

采纳的回答

Walter Roberson
Walter Roberson 2012-5-16
  2 个评论
Jan
Jan 2012-5-16
For some Matlab versions, sum(sum(a))/numel(a) is measurable faster than mean(a(:)) for two reasons: In pre-2011 (don't know exactly the release number) versions of Matlab, sum(A) was vectorized, when A has multiple dimensions, while a vector was processed in one thread only. For very small vectors the overhead of calling the M-file mean mattered.

请先登录,再进行评论。

更多回答(1 个)

Thomas
Thomas 2012-5-16
Don't know if this is better..
a=[2 4 5;3 2 1;2 3 8;4 1 9];
average=mean(mean(a))

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by