I have a matrix which is 1000 columns and 3621 rows, how do I take the mean of each row?

1 回表示 (過去 30 日間)
Basically I want to turn my matrix from dimensions 3621x1000 into 3621x1 by taking the means of each row.
Thank you for your help.

採用された回答

Jacob Ward
Jacob Ward 2017 年 9 月 5 日
In general, if you have a matrix A and want to take the mean across a certain dimension, dim, you should use mean(A,dim).
dim = 1 gives the mean for each column, dim = 2 gives the mean for each row, and so on.
Here's an example for your case:
M = rand(3621,1000);
size(M)
ans =
3621 1000
meanOfEachRow = mean(M,2)
size(meanOfEachRow)
ans =
3621 1

その他の回答 (1 件)

Ahmed Grera
Ahmed Grera 2017 年 9 月 5 日
clc
clear all
a=[1 2 3;4 5 6;7 8 9] % Replace this matrix with your matrix
mean(a,2)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by