RCL=rcofind(s,il)
s : | size of matrix | |
il : | index list |
RCL : | Roews cols list |
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')
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.
[rows, cols]
.il
is a row vector. If not, transpose it to ensure it is a row vector.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.mod1
function, which adjusts the indices to fit within the number of rows specified by s(1)
.il
by the number of rows s(1)
and taking the ceiling of the result.RCL
, where each row contains a pair of row and column indices.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.