MATLAB: Combine 2 vectors to one result vector

arrayvector

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!

Best Answer

idx=replace<0
y1(idx )=y(idx)