MATLAB: Create a new array by summing the columns of old array

arraysMATLABmatrix

I have an array that is 512×64, I would like to sum each consecutive columns until I have a new array that is 512×32,
so old_array column 1 + old_array column 2 = new_ array column 1
old_array column 3 + old_array column 4 = new_ array column 2
old_array column 5 + old_array column 6 = new_ array column 3
etc.
I have tried using a nested for loop but I am unsure what to exceute inside. Thank you for any help!

Best Answer

The MATLAB approach, where M is your matrix:
new = M(:,1:2:end) + M(:,2:2:end);