How to convert row-major linear indices to column-major indices?
23 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Preetham Manjunatha
am 23 Mär. 2022
Kommentiert: Preetham Manjunatha
am 24 Mär. 2022
I have a row-major linear indices [1,8, 14, 9, 4, 11, 18] from a matrix 3 x 6 (row x column). How to convert this to column-major linear indices [1, 5, 6, 8, 10, 14, 18] without for-loops? I want to generalize for any rectangular or square matrices.
0 Kommentare
Akzeptierte Antwort
Stephen23
am 23 Mär. 2022
Bearbeitet: Stephen23
am 23 Mär. 2022
S = [3,6]; % matrix size
X = [1,8,14,9,4,11,18]; % row-major linear indices
[Y,Z] = ind2sub(flip(S),X);
V = sub2ind(S,Z,Y) % column-major linear indices
4 Kommentare
Stephen23
am 24 Mär. 2022
S = [3,6]; % matrix size
X = [1,5,6,8,10,14,18]; % column-major linear indices
[Y,Z] = ind2sub(S,X);
V = sub2ind(flip(S),Z,Y) % row-major linear indices
Siehe auch
Kategorien
Mehr zu Linear Algebra finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!