フィルターのクリア

Sum each element in a matrix with the previous elements on the same diagonal

1 回表示 (過去 30 日間)
Mohamed Abdalmoaty
Mohamed Abdalmoaty 2016 年 2 月 3 日
回答済み: Andrei Bobrov 2016 年 2 月 3 日
I'm looking for an "efficient way", that will work on larger matrices like 2000 by 2000 in reasonable time, to do this operation on a given square symmetric and anti-symmetric matrix (Hankel matrix)
A =[1 2 3;
2 3 4;
3 4 5;];
Then the output should be
B = [1 2 3;
2 4 6;
3 6 9;]

回答 (3 件)

Andrei Bobrov
Andrei Bobrov 2016 年 2 月 3 日
B = fliplr(spdiags(cumsum(spdiags(A))));
B = B(:,all(B));

Walter Roberson
Walter Roberson 2016 年 2 月 3 日
No. Your B(2,1) is 4 even then there is nothing proceeding it on the same diagonal from upper left to lower right. But 4 is the cumulative sum from the diagonals from the upper right to the lower left, the anti-diagonals. This establishes that you want both diagonal and anti-diagonal cumulative sums to be taken. But your B(3,1) is 4, which is not the cumulative sum along the anti-diagonal
x x 3
x 3 x
4 x x
Therefore there is no rule for what values should appear along the left column of B, and therefore the result cannot be computed.
  1 件のコメント
Mohamed Abdalmoaty
Mohamed Abdalmoaty 2016 年 2 月 3 日
Hi, Thanks for your answer. I had a typo in my question. B should be correct now.

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


Ajay Goyal
Ajay Goyal 2016 年 2 月 3 日
編集済み: Ajay Goyal 2016 年 2 月 3 日
Simple Brother, Use a(i,j)=a(i,j)+a(i-1,j-1) in your double loop (for i=1:2000(for rows); for j=1:2000(for columns)) Thanks for accepting the answer formally
  1 件のコメント
Mohamed Abdalmoaty
Mohamed Abdalmoaty 2016 年 2 月 3 日
編集済み: Mohamed Abdalmoaty 2016 年 2 月 3 日
Thanks for your answer, the suggestion is not helpful when you have large matrices. Thanks

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

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by