rcofind

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 4.8, Creation date: 2019-11-24, 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 , indofrc

Example Illustration

 missing image of rcofind(s,il)

Syntax

RCL=rcofind(s,il)

Input Parameter

s: size of matrix
il: index list

Output Parameter

RCL: Roews cols list

Examples


m=5; M=circshift(reshape(1:m*m,m,[]),[floor(randminv(m)),floor(randminv(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')




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, rcofind, is designed to convert a list of linear indices into a list of row and column indices for a matrix. It is particularly useful when working with 2D matrices in MATLAB, where you need to convert a scalar index into its corresponding row and column indices.

Input Parameters

Output

Algorithm Steps

  1. Check if the input index list il is a row vector. If not, transpose it to ensure it is a row vector.
  2. Verify that all indices in il are within the valid range of the matrix size specified by s. If any index exceeds the maximum possible index (i.e., s(1) * s(2)), an error is thrown.
  3. Calculate the row indices using the mod1 function, which adjusts the indices to fit within the number of rows specified by s(1).
  4. Calculate the column indices by dividing each index in il by the number of rows s(1) and taking the ceiling of the result.
  5. Combine the row and column indices into a matrix RCL, where each row contains a pair of row and column indices.

Example Usage

Consider a 5x5 matrix M with some NaN values. The function rcofind can be used to find the row and column indices of these NaN values:

m = 5;
M = circshift(reshape(1:m*m, m, []), [floor(randminv(m)), floor(randminv(m))]);
n = m;
for i = 1:n
    M(floor(randminv(m)), floor(randminv(m))) = nan;
end
l = find(isnan(M));
rcofind(size(M), l);
rcofind(size(M), l');

This example demonstrates how to use the function to convert the linear indices of NaN values into their corresponding row and column indices.

Algorithm explaination created using ChatGPT on 2025-08-19 01:01. (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