Join elements of an array
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Antworten (1)
Azzi Abdelmalek
am 12 Jul. 2015
Bearbeitet: Azzi Abdelmalek
am 12 Jul. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!