Replacing 1's in a vector 'a' with elements of another vector 'b' where a and b are not equal?
Ältere Kommentare anzeigen
I have two vectors 'a' and 'b' in the following form:
a=[nan nan 1 1 nan 1 nan 1 1 1 1]
b=[2 3 4 5 6 7 8]
I want to replace all the 1's in vector 'a' by elements in vector 'b' so that I have a vector 'c' in the following shape:
c=[nan nan 2 3 nan 4 nan 5 6 7 8]
I have vectors 'a' and 'b' having thousands of elements and I want to replace all 1's in vector 'a' by elements in vector 'b' .
Please help
Thanks
Akzeptierte Antwort
Weitere Antworten (1)
Azzi Abdelmalek
am 22 Jul. 2015
a=[nan nan 1 1 nan 1 nan 1 1 1 1]
b=[2 3 4 5 6 7 8]
idx=a==1
a(idx)=b(1:sum(idx))
1 Kommentar
Abdul
am 22 Jul. 2015
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!