MATLAB: How to find a specific row in a matrix and eliminate it

eliminatematrix

Hi everyone, I have a matrix such as this: D0=[1 2;1 4;2 1;3 5;4 1;5 3]. I need to eliminate one of the two rows with same elements. for example, 1 & 2 both involve in rows one and three, so I need to eliminate one of these rows. can any one please help me?

Best Answer

It looks like you don't care about the ordering of the columns. In that case, it's extremely simple: a) sort the rows (so that [2 1] becomes [1 2]) and b) use unique to remove duplicates
D0 = [1 2;1 4;2 1;3 5;4 1;5 3]
uniquerows = unique(sort(D0, 2), 'rows', 'stable')
%if you don't care about the rows ordering you can omit the 'stable'