MATLAB: What is the most efficient way to map big array of [0 1] to [1 -1]

[0 1] to [1 -1] mapping

I want to XOR 2 big array but hit matlab memory limitation. The only way come to my mind is to map [0 1] to [1 -1] and then perform a direct multiplication? What is the most efficient way to do it? I am trying to avoid the for loop to do an element by element operation.

Best Answer

Your problem is very unclear. Where are you hitting the memory limitation? In creating the result of the XOR? In that case, whatever workaround you can find is going to hit that same limitation unless you can somehow reuse the memory of one of the input array (which would involve subverting matlab's memory manager)
You haven't supplied the code you're using but since you mention avoiding a loop, I assume you're using a loop. That's totally unnecessary, matlab already has a function to xor two arrays. Not surprisingly, it's called xor.
Or maybe you want to XOR the bits of the numbers in the arrays. In which case, use bitxor.