The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: indexing surprise
Replies: 7   Last Post: Aug 4, 2011 9:53 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Andreas Lobinger

Posts: 12
Registered: 7/29/11
Re: indexing surprise
Posted: Aug 3, 2011 11:26 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hello colleague,

"Ben" wrote in message <j1bokj$bo8$>...
> "Andreas Lobinger" wrote in message <j1bnbb$777$>...
> > 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(
> >
> > 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,

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.