For my project I have to account for any duplicate columns and remove them, but the original order of the columns must be retained. If I use the method below, the columns in the output get sorted. Is there a way to remove the duplicate columns in a matrix without sorting them?
I have a 2 by 4 matrix A:
A = [7, 2, 1, 9; 3, 2, 9, 11]
a_transpose = A.'
a_no_duplicate = unique(a_transpose, 'rows').'
After running the code, this is the output:
1 2 7 9
9 2 3 11
(Here the columns are sorted)