フィルターのクリア

Addition of 3D matrices

1 回表示 (過去 30 日間)
Azza Ahmed
Azza Ahmed 2012 年 12 月 3 日
Hi,
I have a matrix that looks like this:
M(:,i,X,Y) that gives an answer of another matrix with dimension of 3*1 when multiplied by another matrix of 3*1.
The values for i = 1:5, for X and Y = 1:3, and : is variable.
Now what I want to do is to add together all values of M(:,1,X,Y) {meaning for the whole ranges of X and Y}, and similarly for all of M(:,2,X,Y), M(:,3,X,Y), M(:,4,X,Y) and M(:,5,X,Y).
Would someone kindly show me how to do that?
BW AA
  1 件のコメント
Jan
Jan 2012 年 12 月 3 日
Do I understand correctly: You have a Matrix M of the size [N x 5 x 3 x 3]?

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

回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 12 月 3 日
squeeze(sum(M,1))

Jan
Jan 2012 年 12 月 3 日
Perhaps this helps:
n = 100;
M = rand(n, 5, 3, 3);
P = reshape(permute(M, [1,3,4,2]), n * 3 * 3, 5);
Result = sum(P, 4);

カテゴリ

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