Matrix calculation to find the average value

1 回表示 (過去 30 日間)
Prabha Kumaresan
Prabha Kumaresan 2017 年 12 月 6 日
コメント済み: Prabha Kumaresan 2017 年 12 月 6 日
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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by