MATLAB: Remove the rows/columns with single values of a matrix

columncolumnseliminateeraseMATLABrowrows

Hello,
I have a matrix quite big (A < 23 x 250000 >). I want to evaluate the first row A(1,:) and eliminate the columns where there are values only repeated once. The number in this first row is an integer and always is increasing.
Lets say:
B = [1 1 3 5 5 5 7 9 9
0.1 0.5 0.2 0.4 0.3 0.9 0.1 0.6 0.5]
The result should be:
B = [1 1 5 5 5 9 9
0.1 0.5 0.4 0.3 0.9 0.6 0.5]
I know how to do it with for and if statements but I think it won't be efficient because the size of the matrix.
Many thanks!

Best Answer

This is the code I have and it works, but maybe it is not efficient:
for i = 2:length(A) - 1;
if A(1,i) ~= A(1,i-1) && A(1,i) ~= A(1,i+1)
A = A(:,[1:i-1 i+1:end]);
i = i - 1;
end
end