How you would write this code depends on how you want to do the function on the matrix rows:
- Option 1: rows 1&2, then rows 3&4, then rows 5&6, and so on
- Option 2: rows 1&2, rows 2&3, rows 3&4, and so on
For both cases, you can use a for loop and use the size() function to find the number of rows of the matrix you are using. size(mat,1) will give you the number of rows and size(mat,2) will give you the number of columns of the matrix "mat".
If you're looking to do option 1, you could do the following:
For option 2, you would make some slight changes to the above code, mainly not incrementing the for loop by 2 and not needing to check to make sure you don't try to index rows of the matrix that don't exist.