matrix addition and calculating the average of it

1 visualización (últimos 30 días)
Prabha Kumaresan
Prabha Kumaresan el 6 de Dic. de 2017
Editada: Stephen23 el 6 de Dic. de 2017
how to add the three matrix and get the average of it A=rand(4*4) B=rand(4*4) C=rand(4*4)

Respuestas (1)

Benjamin Kraus
Benjamin Kraus el 6 de Dic. de 2017
You can add three matrices using the + operator, which will do element-by-element addition:
D = A+B+C;
If you want to get the mean/average, you can divide the sum by 3:
M = D./3;
Note: In this case, you are dividing by a scalar (3), so ./ and / will do the same thing. If you were dividing by a matrix you would need to make sure to use the correct division operator.
  2 comentarios
Prabha Kumaresan
Prabha Kumaresan el 6 de Dic. de 2017
thanks for your comment.but if i want to add m number of matrix instead of 3 then how i do that.Also for calculating mean i want to add the numbers in first column together and then divide by 3.so it results in (1*3) matrix.
Stephen23
Stephen23 el 6 de Dic. de 2017
Editada: Stephen23 el 6 de Dic. de 2017
"...but if i want to add m number of matrix instead of 3 then how i do that"
Read this to know why that would be a really bad way to write code:
Put all of the matrices into one array (ND numeric or cell) and then your task is trivial.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by