I have a 2d matrix, i want to traverse all elements in this matrix something like this:
a =
0 1 2
5 4 3
6 7 8
for i = 1 : 81
a(i) = ....
....
now, for example when i use a(2), i received “5”, but i want a(2) give me “1”. in the other word, i want use linear indexing with rows traversal instead of columns.
To traverse an array down rows try something like this. Here
ahascol_countcolumns androw_countrowsThis will print out your elements in turn starting with first column, printing element of each row in that column in row order. This is repeated for each column.
edit: If you must use a single index then just use your current single index notation, but act on the transpose of your matrix: