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
- ni: A vector containing the sizes of elements. Each entry in this vector represents the size of a corresponding element.
Output Results
- il: A matrix where each row contains two values: the start index and the end index of each element based on the sizes provided in
ni
.
Algorithm Steps
- 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
.
- 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.
- 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
.
- 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
.
- 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