problem of matrix operations

1 回表示 (過去 30 日間)
mahesh chathuranga
mahesh chathuranga 2013 年 9 月 30 日
編集済み: Andrei Bobrov 2013 年 10 月 3 日
i have a n*n matrix. i want to obtain (row number-column number) matrix.for a 4*4 matrix result should be
[0 -1 -2 -3;
1 0 -1 -2;
2 1 0 -1;
3 2 1 0];
i want to do this for any (n*n) matrix.is there any method to do this.

採用された回答

Honglei Chen
Honglei Chen 2013 年 9 月 30 日
You can do
rownumber = 4
colnumber = 4
bsxfun(@minus,(1:rownumber)',1:colnumber)
Or considering the special form of this matrix, you can just do
toeplitz((0:rownumber-1)',0:-1:-colnumber+1)
  1 件のコメント
mahesh chathuranga
mahesh chathuranga 2013 年 10 月 3 日
thnk you verymuch

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

その他の回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 30 日
a=rand(4) % Example
n=size(a,1)
bsxfun(@minus,repmat((1:n)',1,n),(1:n))
  1 件のコメント
mahesh chathuranga
mahesh chathuranga 2013 年 10 月 3 日
thanks

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


Andrei Bobrov
Andrei Bobrov 2013 年 9 月 30 日
編集済み: Andrei Bobrov 2013 年 10 月 3 日
toeplitz(0:3,-(0:3))
  1 件のコメント
mahesh chathuranga
mahesh chathuranga 2013 年 10 月 3 日
thank you

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

カテゴリ

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