indofrc
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 4.8, Creation date: 2019-11-25, Last change: 2025-09-14
converts an index list into a rows cols list
Description
call a matrix with a running index or search in a 2D matrix such as isnan returns a scalar value. This function converst the scalar value into rows and cols wrt the matlab rules.
See Also: GPLofmatrix
, matrixneighbors
, matrixvalues
, matrixdistancefield
, rcofind
Example Illustration
Syntax
ind=indofrc(Ms,PL)
Input Parameter
Ms: | | size of matrix |
PL: | | rc list |
Output Parameter
Examples
m=5; M=reshape(1:m*m,m,[])
n=m; for i=1:n; M(floor(randminv(m)),floor(randminv(m)))=nan; end; M
l=find(isnan(M))
rcofind(size(M),l)
rcofind(size(M),l')
indofrc(size(M),ans)
Copyright 2019-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, indofrc, converts a list of row-column indices into a list of linear indices based on the size of a matrix. It is part of the SG-Library and was introduced in SolidGeometry 4.8.
Input Parameters
- Ms: A vector representing the size of the matrix. It typically contains two elements, where
Ms(1) is the number of rows and Ms(2) is the number of columns.
- PL: A matrix where each row represents a pair of row and column indices. The first column contains row indices, and the second column contains column indices.
Output
- ind: A column vector containing linear indices corresponding to the row-column pairs in
PL.
Algorithm Steps
- Initialize
ind as a zero vector with the same number of rows as PL.
- Iterate over each row of
PL:
- For each row
i in PL, calculate the linear index using the formula: (PL(i,1)-1)*Ms(1) + mod1(PL(i,2),Ms(1)).
- Store the calculated index in
ind(i).
Explanation of Formula
The formula (PL(i,1)-1)*Ms(1) + mod1(PL(i,2),Ms(1)) is used to convert 2D indices to a linear index:
PL(i,1)-1 adjusts the row index to zero-based indexing.
*Ms(1) scales the row index by the number of rows to account for the full rows before the current one.
mod1(PL(i,2),Ms(1)) adjusts the column index to fit within the matrix size.
Example
Consider a 5x5 matrix M with some NaN values. The function find(isnan(M)) returns linear indices of NaN values. rcofind(size(M),l) converts these to row-column pairs, and indofrc(size(M),ans) converts them back to linear indices.
Algorithm explaination created using ChatGPT on 2025-08-19 00:14. (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