ind=indofrc(Ms,PL)
Ms : | size of matrix | |
PL : | rc list |
ind : | index list |
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)
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.
Ms(1)
is the number of rows and Ms(2)
is the number of columns.PL
.ind
as a zero vector with the same number of rows as PL
.PL
:i
in PL
, calculate the linear index using the formula: (PL(i,1)-1)*Ms(1) + mod1(PL(i,2),Ms(1))
.ind(i)
.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.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.