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 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