更新时间:2022-04-20 21:09:52
This is not something I've used before, but according to this handy dandy Matlab to R cheat sheet, you might try something like this, where m
is the number of rows in the matrix, r
and c
are row and column numbers respectively, and ind
the linear index:
MATLAB:
[r,c] = ind2sub(size(A), ind)
R:
r = ((ind-1) %% m) + 1
c = floor((ind-1) / m) + 1
MATLAB:
ind = sub2ind(size(A), r, c)
R:
ind = (c-1)*m + r