size2index

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 2.7, Creation date: 2015-10-04, Last change: 2025-09-14

converts a size list into an index list [start end]

Description

The size list contains element sizes [n1 n2 n3 n4 n5..]
The index list contains elements of type [startindex endindex]
Backwards it is: index2size = il(:,2)-il(:,1)+1

Example Illustration

 missing image of size2index(ni)

Syntax

il=size2index(ni)

Input Parameter

ni: list of [size of element]

Output Parameter

il: list of [startindex endindex]

Examples


size2index([1 3 4 3])




Copyright 2015-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, size2index, converts a list of element sizes into a list of index ranges. It is designed to work with a vector of sizes and outputs a matrix where each row represents the start and end indices of each element.

Input Parameters

Output Results

Algorithm Steps

  1. Check if ni is a column vector (i.e., it has more than one row). If so, transpose it to ensure it is a row vector. This is done using the condition size(ni,1)>1.
  2. Calculate the cumulative sum of the sizes in ni and prepend a zero to this cumulative sum. This is stored in vector a. The cumulative sum helps in determining the end index of each element.
  3. Calculate the start indices of each element by taking all but the last element of a and adding 1 to each. This is stored in vector b.
  4. Calculate the end indices of each element by adding the sizes in ni to the start indices in b and subtracting 1. This is stored in vector c.
  5. Combine b and c into a two-column matrix il, where each row represents the start and end indices of an element.
Algorithm explaination created using ChatGPT on 2025-08-18 22:09. (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