# How to make 2 matrix out of 1 one matrix??

1 vue (au cours des 30 derniers jours)
Ali nouri le 25 Juin 2020
Commenté : Alan Stevens le 26 Juin 2020
Hi Guys,
I have a 8760X30 matrix, which is included with the positive and negative number. Now I want to make 2 matrix of the originally matrix with the same dimension.
The difference is in one matrix should included the possitive number from the originally matrix and replace the negatives with zero, and in the other matrix should included with negative value and replace positive number with zero.
How can I do it?
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Alan Stevens le 25 Juin 2020
If your first matrix is A, then:
ix = find(A>0); B = A; B(ix) = 0;
ix = find(A<0); C = A; C(ix) = 0;
##### 2 commentairesAfficher AucuneMasquer Aucune
Sugar Daddy le 26 Juin 2020
using find is inefficient in such kind of scenaria.
Alan Stevens le 26 Juin 2020
I agree that the "find" version is not the most efficient. However, sometimes clarity is more important than efficiency, and I suggest that, for a novice, the "find" version is clearer.

Connectez-vous pour commenter.

### Plus de réponses (1)

Sugar Daddy le 25 Juin 2020
Modifié(e) : madhan ravi le 26 Juin 2020
Aneg = (A<0) .* A
Apos = (A>0) .* A
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Sugar Daddy le 26 Juin 2020
beauty madhan

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Logical 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