Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: indexing surprise
Posted:
Aug 3, 2011 11:26 AM


Hello colleague,
"Ben" wrote in message <j1bokj$bo8$1@newscl01ah.mathworks.com>... > "Andreas Lobinger" wrote in message <j1bnbb$777$1@newscl01ah.mathworks.com>... > > Hello colleagues, > > i'm now into debugging for some time (~ 1h) until i recognized that Matlab > > has a quite surprising way of creating new variables. > > ... > > And now the punchline: > > > > >> a(idx_new) = par.height(net.bt(idx_new)) > > > > a = > > > > 10.5000 10.5000 10.5000 > > > > so although my righthand side is a column vector and my index to a is a > > column vector , the result in the new created a is a row vector.
> The moral of the example: If you want to store your vector in a column, you need to specify that directly.
Which is what i do now in the program. I had for some time the impression that the size of the index defines the field. > As to why that is, I'm guessing a bit here, so I hope someone corrects me if I'm off, but I think MATLAB stores things in a row because it's faster. (If you do indexing through a matrix row by col vs col by row, you will see different speeds for large matrices.
This may be, however my experiences with linear addressing (which i use quite a lot) is that a linear index goes first dimenstion which means columnwise first.
But all this maybe have some historical backwards compatibility reasons.
Wishing a happy day, Andreas



