Calculate mean value from different matrices

12 ビュー (過去 30 日間)
Mepe
Mepe 2020 年 12 月 30 日
コメント済み: Ameer Hamza 2020 年 12 月 30 日
Hi there,
I have 5 different matrices (10x10000), where I want to calculate the mean value of the individual rows column by column, so that the end result is a single 10x10000 matrix. How can I do this most elegantly with the "mean" command?
  1 件のコメント
Image Analyst
Image Analyst 2020 年 12 月 30 日
How do you end up with the same size result? If you have a 10x10000 matrix, then taking the mean of rows, going across columns, is like this
rowMeans1 = mean(M1, 2); % Result is a 10 x 1 vector.
and the result is a 10 x 1 vector. So if you had 5 or those, even if you stitched them together you'd have a 10x5 matrix.
overallResults = [rowMeans1, rowMeans2, rowMeans3, rowMeans4, rowMeans5]; % 10x5
Or if you went in the other direction
columnMeans1 = mean(M1, 1); % Result is a 1 x 10000 vector.
Stitching together 5 of them would give a 5x10000 matrix.
overallResults = [rowMeans1; rowMeans2; rowMeans3; rowMeans4; rowMeans5]; % 5x10000

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 12 月 30 日
How are 5 matrices available? Is it a cell array? Try something like this
C = {M1, M2, M3, M4, M5};
M = cat(3, C{:});
M_mean = mean(M, 3)
  4 件のコメント
Image Analyst
Image Analyst 2020 年 12 月 30 日
編集済み: Image Analyst 2020 年 12 月 30 日
Of course creating a cell array is not needed. You could just omit that and do
M = cat(3, M1, M2, M3, M4, M5);
M_mean = mean(M, 3);
Just to clarify Mepe, you're not using "column" in the usual sense of a matrix, as in rows and columns, like everyone else does. This is taking the average of all matching coordinates across 5 different matrices, not column-by-column, hence my question above asking for clarification. Evidently Ameer also has a beta copy of the Mind Reading Toolbox.
Ameer Hamza
Ameer Hamza 2020 年 12 月 30 日
I wish I could subscribe to that toolbox :D . I just guessed based on confusing wording in the question and the intended size of the output matrix.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall C++ from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by