finddoubledrows

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

returns the indices of the lines with copies of a earlier row



See Also: flipvar

Example Illustration

 missing image of finddoubledrows(VL)

Syntax

c=finddoubledrows(VL)

Input Parameter

VL: list of rows

Output Parameter

c: indices of the second, third, and so on, occur to be removed

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,:)




Copyright 2018-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

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.

Input Parameters

Output Results

Algorithm Explanation

  1. The function uses the 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.
  2. The unique function returns two outputs: the unique rows and their indices. Here, only the indices, b, are used.
  3. The 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.
  4. The result, c, is a vector of indices representing the duplicate rows, excluding the first occurrence of each duplicate.

Example Usage

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)

Last html export of this page out of FM database by TL: 2025-09-21