MATLAB: Selecting Every Other Element in a Matrix

elementevery othermatrix

How can I select every other element in a matrix, such as A=[1 2 8 7 6 5 4 6]?

Best Answer

I’m not certain what you want, so I’ll venture two possibilities:
A=[1 2 8 7 6 5 4 6];
Aodd = A(1:2:end); % Odd-Indexed Elements
Aeven = A(2:2:end); % Even-Indexed Elements