mean value of each row

221 ビュー (過去 30 日間)
ava
ava 2012 年 2 月 5 日
コメント済み: Walter Roberson 2021 年 9 月 2 日
I have A 500 by 16 matrix and I want to find a mean value of each row and return the result as a 500 by 1.
Does anyone have an idea?
Thank you
  2 件のコメント
Walter Fanka
Walter Fanka 2018 年 7 月 15 日
編集済み: Walter Roberson 2018 年 7 月 17 日
y = yourmatrix;
meanrow_y = mean(y')'
Walter Roberson
Walter Roberson 2018 年 7 月 17 日
That should work for 2D arrays like were asked about. However for 3 or more dimensions it would not work and you would need to use a couple of permute() instead. It is a lot easier to just pass in the dimension number like I showed in my Answer.

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

採用された回答

Walter Roberson
Walter Roberson 2012 年 2 月 5 日
mean(YourMatrix,2)
  4 件のコメント
Jan
Jan 2017 年 3 月 15 日
The documentation of mean explains this exhaustively already:
doc mean
The first input is the data, the 2nd the dimension to operate on. Therefore mean(x,2) is the mean over the 2nd dimension, which means the rows.
Amy Gleckl
Amy Gleckl 2019 年 12 月 20 日
I had a similar issue and this worked perfectly for me, thank you very much!

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

その他の回答 (2 件)

sura Naji
sura Naji 2019 年 10 月 25 日
l have amatrix contact from 1 colum and 1000 rows l want to find the mean and the standard deviation also l want to find the worst value of this because l use the particle swarm optimization
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 12 月 22 日
M = mean(amatrix);
S = std(amatrix);
[~, order] = max(abs(amatrix - M));
furthest_from_mean = amatrix(order(1));
Note that the value that is furthest from the mean will also be the value that is the greatest zscore (furthest deviation)

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


RAMPUNIT KUMAR
RAMPUNIT KUMAR 2021 年 9 月 2 日
RAMPUNIT KUMAR less than a minute ago ⋮ I too have a doubt, like for matrix (a b c d e f g h I j k l m n o p q r) I need to find the mean of a,b then c,d then e,f then g,h and so on upto last element. How could we do that if size is big enough.
  1 件のコメント
Walter Roberson
Walter Roberson 2021 年 9 月 2 日
syms a b c d e f g h I j k l m n o p q r
matrix = [a b c d e f g h I j k l m n o p q r]
matrix = 
means = (matrix(1:2:end) + matrix(2:2:end))/2
means = 
except that you would use the appropriate numeric values in matrix instead of syms . The syms used here is just for demonstration purposes.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by