Filling vector with a condition.
Afficher commentaires plus anciens
Hi.
I have two vectors A and B of the same length
I wan´t to create a new vector containing the same numbers of B, but only if the same element in A was a number>0, if not, i want to put a zero in that element.
How can i do this? Could you help me?
Thank you in advance!!
Réponse acceptée
Plus de réponses (1)
Like this?
A = [1 2 -3 0 4 0 -5 0 6];
B = 10:19;
C = zeros(1,length(A));
C(A>0) = B(A>0)
C =
10 11 0 0 14 0 0 0 18
1 commentaire
Javier
le 9 Mai 2013
Catégories
En savoir plus sur Assembly dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!