Dimension 1 and dimension 2 in octave

534 Views Asked by At

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 ?

1

There are 1 best solutions below

0
On

Yeah, that can be a bit confusing. Try to think about it this way:

1 = which row 2 = which column

max(r,[],1) = "get the biggest row" (which of course might be a mixture of different rows).

max(r,[],2) = get the biggest column

Hope this helps to see the reason for this. For matrices it would be possible to use a different convention which might look more intuitve for you. But for higher rank objects (i.e. more than two indices), this convention is the only sensible.