# Dimension 1 and dimension 2 in octave

I have this in octave:

octave:139> r
r =

3   1
7   2

octave:140> r(2,:)
ans =

7   2

octave:141> r(1,1)
ans =  3
octave:142> r(1,2)
ans =  1


This kind of indexing indicates to me that the dimension 1 is row and dimension 2 is column.

But down below when I specify dimension 1, I get max along the columns (now rows)

octave:143> max(r,[],1)
ans =

7   2


And here when I specify dimension 2, I get max along the rows (now colums)

octave:144> max(r,[],2)
ans =

3
7


Why so ?

I think a more sensible answer is that the DIM input tells Octave which dimension to take as the independent variable. That is, for example in sum(X, DIM) with DIM =1, at each step the summation is done along the vertical direction (first dimension), which corresponds to the rows as you have observed in your first examples, and the result is a function of the horizontal direction, much like in a double integral.