Matrix calculation to find the average value

1 次查看(过去 30 天)
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]

回答(1 个)

Adam
Adam 2017-12-6
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 个评论
Adam
Adam 2017-12-6
编辑:Adam 2017-12-6
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.
Prabha Kumaresan
Prabha Kumaresan 2017-12-6
i want to add multidimensional array for the following command output_it(t,r,it) where output_it is 5*5*5 double t is 1*1 double =5 r is 1*1 double=5 it is 1*1 double=5

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by