indexvariant
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 5.3, Creation date: 2023-03-21, Last change: 2025-09-15
creates multidimensional index sequences for testing or other purposes
Description
much faster than permutevector - for different input vectors use permutevarargin
See Also: permutevector
Example Illustration
Syntax
zz=indexvariant([vec,dim])
Input Parameter
vec: | | row or col vector; default is [1 2 3] |
dim: | | integer as dimension; default is 2 |
Output Parameter
zz: | | index field [numel(vec)^dim x dim] |
Examples
zz=indexvariant([1:3],1); zz, whos zz
zz=indexvariant([1:3],2); zz, whos zz
zz=indexvariant([1:3],3); zz, whos zz
zz=indexvariant([1:3],4); zz, whos zz
Copyright 2023-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, indexvariant, generates multidimensional index sequences. It is designed to be faster than permutevector and is part of the SolidGeometry library.
Input Parameters
- vec: A row or column vector. The default value is
[1 2 3].
- dim: An integer representing the dimension. The default value is
2.
Output
- zz: An index field with dimensions
[numel(vec)^dim x dim].
Algorithm Steps
- Retrieve the input parameters
vec and dim using the getfuncparams function. If not provided, use default values.
- Adjust
dim by subtracting 1 to align with zero-based indexing.
- If
vec is a row vector, transpose it to a column vector.
- Initialize
zz with vec.
- Iterate from 1 to
dim:
- Repeat
zz n times using repmat and store in oo.
- Repeat
vec n^k times, reshape it, and store in uu.
- Reshape
uu to have dimensions [n^(k+1), 1].
- Concatenate
oo and uu to form the new zz.
Example Usage
Examples of how to use the function:
zz=indexvariant([1:3],1);
zz=indexvariant([1:3],2);
zz=indexvariant([1:3],3);
zz=indexvariant([1:3],4);
Algorithm explaination created using ChatGPT on 2025-08-19 00:49. (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