reversesortindex

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 3.9, Creation date: 2017-06-09, Last change: 2025-09-14

returns the reverse sort index for a sort index

Description

rO=sortrows([iO [1:size(iO)]']); rO=rO(:,2);

See Also: maprows , VLFLreorder , VLcorrelate

Example Illustration

 missing image of reversesortindex(iO)

Syntax

rO=reversesortindex(iO)

Input Parameter

iO: result of sortrows

Output Parameter

rO: reverse sort order

Examples


A=SGbox([30 20 10]);
VL=A.VL, [VL,a]=sortrows(VL), b=reversesortindex(a)
SGfigure; VLFLplot(VL,b(FL),'y');




Copyright 2017-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, reversesortindex, is designed to compute the reverse sort index for a given sort index. It is part of the SolidGeometry library and was introduced in version 3.9.

Input Parameters

Output Results

Algorithm Explanation

The function works as follows:

  1. It takes the input array iO, which is assumed to be the result of a sortrows operation.
  2. It constructs a new matrix by appending a column to iO. This new column is a sequence of indices from 1 to the number of elements in iO.
  3. The function then applies sortrows to this new matrix. The sorting is done based on the original values in iO, but the result includes the appended indices.
  4. Finally, the function extracts the second column of the sorted matrix, which contains the indices that map the sorted array back to its original order. This is the reverse sort index rO.

Example Usage

Consider the following example:

A = SGbox([30 20 10]);
VL = A.VL;
[VL, a] = sortrows(VL);
b = reversesortindex(a);
SGfigure;
VLFLplot(VL, b(FL), 'y');

In this example, a box is created with dimensions 30x20x10. The vertices list VL is sorted, and then the reverse sort index is computed using reversesortindex. Finally, the vertices are plotted in their original order.

Algorithm explaination created using ChatGPT on 2025-08-18 23:00. (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