Matrix calculation to find the average value
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
A=[1 2 3 4; 5 6 7 8; 9 10 11 12;] B=[13 14 15 16; 17 18 19 20; 21 22 23 24;] C=[25 26 27 28; 29 30 31 32; 33 34 35 36;]
how to add all the matrix such that it should result in D=[39 42 45 48; 46 54 51 60; 63 66 69 72;] and i need to calculate the average value of D which results in [(39+46+63)/3 (42+54+66)/3 (45+51+69)/3 (48+60+72)/3]
Respuestas (1)
Adam
el 6 de Dic. de 2017
D = A + B + C
works fine and is surely obvious?!
mean( D )
will then give you the result you want, although your numbers appear incorrect for the example you gave.
3 comentarios
Adam
el 6 de Dic. de 2017
Editada: Adam
el 6 de Dic. de 2017
It depends how you have your n matrices stored. If they are all individually named variables then you already have problems. If they are in a multi-dimensional array of one dimension larger than the individual matrices then
doc sum
will work fine with the correct dimension used for the sum.
You should make this clear in your question though as adding and averaging N matrices is significantly different from 3 hard-coded matrices which is what you asked.
Simplifying a problem to ask a concise question is fine only if you don't simplify out the complexity you actually want to ask about.
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!