Replacing 1's in a vector 'a' with elements of another vector 'b' where a and b are not equal?
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 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))
See Also
Categories
Find more on NaNs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!