简体   繁体   中英

Find row and columns of matrix index in MATLAB

I want to ask something, is there any way to get the row number and column number if I know the index number of a matrix? For example, I have A= 3x3 matrix, and I want to find the row and column for index number 5 on the matrix. The answer should be like this: rows=2 columns=2.

Thank you! Please help me out. I've been stuck on this for a while now. :(

Perhaps try ind2sub ?

IND = [3 4 5 6]
s = [3,3];
[I,J] = ind2sub(s,IND)

I =
     3     1     2     3

J =
     1     2     2     2

Via

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM