combine 2 vectors to one result vector

Dear all,
These are my arrays:
y = [94 96 96 94 89 92 90 89 88 92 93 91 91 91 90 88 90 87 90 91];
y1 = [95 93 94 92 95 93 90 91 92 92 91 87 88 90 96 95 92 91 94 93];
x = [1 2 3 5 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
replace = [0 0 2 -5 0 1 0 0 0 -8 -1 0 0 4 0 0 0 -1 -2 0 ];
The y is my raw data, the y1 is my filtered data, x is the x data and replace is the array with statements to replace vectors in y1.
So now I have to replace the value in y1 with the y value where the replace vector is <0. How do I do this?
Thanks!

 Accepted Answer

madhan ravi
madhan ravi on 30 Oct 2018
Edited: madhan ravi on 30 Oct 2018
idx=replace<0
y1(idx )=y(idx)

4 Comments

By logical indexing you can do it
if you got the answer for your question make sure to accept the answer so that people know question is solved
Thanks it works!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!