MATLAB: How to remove column with the same value

column remove

Hi,
I have this matrix;
A = [0 0 0 0 1 1 1 1 2 2]
I want
  • to remove the 2nd, 3rd and 4th columns since their values are the same as the 1st column,
  • to remove the 6th, 7th and 8th columns since their values are the same as the 5th column,
  • and to to remove the 10th column since its value is the same as the 9th column.
So it becomes
B = [0 1 2]
Regards,
Thank you

Best Answer

B=unique(A)