Take average of multiple matrices

2 ビュー (過去 30 日間)
Amir Hosein Shokouhy
Amir Hosein Shokouhy 2021 年 4 月 8 日
コメント済み: KSSV 2021 年 4 月 8 日
Hello,
I have a variable that contains 5 matrices (6*5) inside it. I want to take the average of these matrices and store it in a 6*5 matrix. I would greatly appreciate it if you could help me with that. I will attach the variable to this post.
Thanks,
Amir

採用された回答

William Rose
William Rose 2021 年 4 月 8 日
Here is a solution:
>> D=open('data.mat');
>> phi=D.phi_BFD_v_sum;
>> phiAvg=zeros(6,5);
>> for i=1:5, phiAvg=phiAvg+phi{i}/5; end
>> disp(phiAvg)
0 0 0 0 0
0.2284 0.6080 0.8000 0.7058 0.4388
0.4377 0.8000 0.2495 -0.5222 -0.7138
0.6112 0.4325 -0.7374 -0.2847 0.7672
0.7355 -0.2412 -0.4568 0.7297 -0.5588
0.8000 -0.7481 0.6222 -0.3616 0.2122
>>
  2 件のコメント
Amir Hosein Shokouhy
Amir Hosein Shokouhy 2021 年 4 月 8 日
Thanks William, it works!
KSSV
KSSV 2021 年 4 月 8 日
You need not to use loop to achieve this. Did you see the other answers?

サインインしてコメントする。

その他の回答 (2 件)

KSSV
KSSV 2021 年 4 月 8 日
load data.mat ;
A = cat(3,phi_BFD_v_sum{:}) ;
iwant = mean(A,3) ;

per isakson
per isakson 2021 年 4 月 8 日
Try this
%%
load('data.mat')
num = cat( 3, phi_BFD_v_sum{:} );
avg = mean( num, 3 );
peek
>> avg
avg =
0 0 0 0 0
0.22843 0.60803 0.8 0.70577 0.43885
0.43769 0.8 0.2495 -0.52216 -0.71376
0.61117 0.4325 -0.73741 -0.28474 0.76717
0.7355 -0.24119 -0.45683 0.72973 -0.55882
0.8 -0.74809 0.6222 -0.36164 0.21224

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by