How to transpose certain elements in a matrix

4 vues (au cours des 30 derniers jours)
Omar Alamoudi
Omar Alamoudi le 2 Jan 2018
Commenté : Omar Alamoudi le 2 Jan 2018
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 :)

Réponse acceptée

Walter Roberson
Walter Roberson le 2 Jan 2018
B = A.*(A<0) + (A.*(A>0)).' ;
  1 commentaire
Omar Alamoudi
Omar Alamoudi le 2 Jan 2018
That was very efficient and neat. Thank you so much :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by