A = [1 ,0, 2, 0, 3, 0, 5];
B = [0, 2, 0, 3, 0, 5, 0];
C = A + B
Or if the zeros need not be at the same indices as the non-zeros in the other variable:
C = A;
C(A == 0) = B(B ~= 0)
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!