To make the swap, you'll need a temporary variable. Extra Credit: Once you got swap working with integers, can you do it with binary vectors, without using a temporary variable? E.g., >> a = [0 1 1 0 1]; >> b = [1 0 1 0 0]; >> bswap a = [1 0 1 0 0] b = [0 1 1 0 1] Hint: This is a classic programming-language-job interview question. GIYF.