Join elements of an array
Afficher commentaires plus anciens
If I have two array
a=[1 2 3 0]
b=[0 0 5 4]
and I want the array c=[1 2 3 4] How should I proceed?
In other words I want a array c in which the element of array a==0 is replaced with the element of matrix b.
1 commentaire
Image Analyst
le 12 Juil 2015
What happened to the 5? Why did you leave that out of c?
Réponses (1)
Azzi Abdelmalek
le 12 Juil 2015
Modifié(e) : Azzi Abdelmalek
le 12 Juil 2015
a=[1 2 3 0]
b=[0 0 5 4]
idx=a==0
bb=sort(nonzeros(b))
a(idx)=bb(1:sum(idx))
2 commentaires
fede
le 12 Juil 2015
Modifié(e) : Azzi Abdelmalek
le 12 Juil 2015
Azzi Abdelmalek
le 12 Juil 2015
Have you tried my code?
Catégories
En savoir plus sur Resizing and Reshaping Matrices 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!