How to transpose certain elements in a matrix

1 回表示 (過去 30 日間)
Omar Alamoudi
Omar Alamoudi 2018 年 1 月 2 日
コメント済み: Omar Alamoudi 2018 年 1 月 2 日
Hi,
I have 5by5 matrix, A:
0 9 2 0 0
0 0 0 1 0
0 3 0 5 0
0 0 0 -3 0
0 0 -1 8 0
where I want to transpose only the positive numbers.
Note: The corresponding transposed location is always zero.
so the answer should look like this, B:
0 0 0 0 0
9 0 3 0 0
2 0 0 0 0
0 1 5 -3 8
0 0 -1 0 0
Thanks a lot for your help :)

採用された回答

Walter Roberson
Walter Roberson 2018 年 1 月 2 日
B = A.*(A<0) + (A.*(A>0)).' ;
  1 件のコメント
Omar Alamoudi
Omar Alamoudi 2018 年 1 月 2 日
That was very efficient and neat. Thank you so much :)

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by