Borrar filtros
Borrar filtros

finding the a average of matrix any better way

1 visualización (últimos 30 días)
Sharon
Sharon el 16 de Mayo de 2012
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..

Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de Mayo de 2012
  2 comentarios
Sharon
Sharon el 16 de Mayo de 2012
thanks Walter..
Jan
Jan el 16 de Mayo de 2012
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.

Iniciar sesión para comentar.

Más respuestas (1)

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

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by