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

 missing image of indofrc(Ms,PL)

Syntax

ind=indofrc(Ms,PL)

Input Parameter

Ms: size of matrix
PL: rc list

Output Parameter

ind: index list

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

Output

Algorithm Steps

  1. Initialize ind as a zero vector with the same number of rows as PL.
  2. Iterate over each row of PL:

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:

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