Mean of matrix by columns

1 回表示 (過去 30 日間)
Alessandro Masullo
Alessandro Masullo 2013 年 10 月 13 日
コメント済み: Alessandro Masullo 2013 年 10 月 13 日
Hello! I'm looking for a function to get the mean of two (or more) columns:
A = 1 2 3
4 5 6
7 8 9
f(A) =
1.5000 2.5000
4.5000 5.5000
7.5000 8.5000
How can I do that in a simple way, for a generic matrix? Thank you.

採用された回答

Andrei Bobrov
Andrei Bobrov 2013 年 10 月 13 日
conv2(A,[.5 .5],'valid')
  1 件のコメント
Alessandro Masullo
Alessandro Masullo 2013 年 10 月 13 日
Thank you!!

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

その他の回答 (2 件)

sixwwwwww
sixwwwwww 2013 年 10 月 13 日
編集済み: sixwwwwww 2013 年 10 月 13 日
Dear Alessandro, you can use MATLAB function "mean" for this purpose. Here is description: http://www.mathworks.com/help/matlab/ref/mean.html. In Your case just use
mean(A)
  6 件のコメント
Alessandro Masullo
Alessandro Masullo 2013 年 10 月 13 日
Yes, this is what I'm trying to do :D I don't want to bug you, but I'm trying to do this with matrix indexing, because I already do this with a loop, but I have very big matrix and the same operation to be done on different matrix of different sizes...
sixwwwwww
sixwwwwww 2013 年 10 月 13 日
I think in anyway you will need to use at least one for loop. However if I will have better idea then I will come back to it

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


Jan
Jan 2013 年 10 月 13 日
B = (A(1:end-1) + A(2:end)) * 0.5

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by