by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 4.3, Creation date: 2018-09-11, Last change: 2025-09-14
See Also: flipvar
c=finddoubledrows(VL)
VL: | list of rows |
c: | indices of the second, third, and so on, occur to be removed |
A=[7 9 8 1 2 3 4 5 3 6 4 5]';
finddoubledrows(A), A(ans)
A=[0 0; 1 0 ; 2 0; 4 0; 1 0];
finddoubledrows(A), A(ans,:)
This function, finddoubledrows, identifies duplicate rows in a given matrix or list of rows, VL. It returns the indices of the second, third, and subsequent occurrences of any duplicate rows.
unique function with the 'rows' and 'stable' options to find unique rows in VL. The 'stable' option ensures that the order of the first occurrence of each unique row is preserved.unique function returns two outputs: the unique rows and their indices. Here, only the indices, b, are used.setdiff function is then used to find the difference between the complete set of row indices (from 1 to the number of rows in VL) and the indices of the unique rows, b.c, is a vector of indices representing the duplicate rows, excluding the first occurrence of each duplicate.Consider the following examples:
A = [7 9 8 1 2 3 4 5 3 6 4 5]'; finddoubledrows(A), A(ans) A = [0 0; 1 0; 2 0; 4 0; 1 0]; finddoubledrows(A), A(ans,:)
In the first example, the function identifies duplicate elements in a column vector. In the second example, it identifies duplicate rows in a matrix.
Algorithm explaination created using ChatGPT on 2025-08-18 22:30. (Please note: No guarantee for the correctness of this explanation)