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
indexing surprise
Posted: Aug 3, 2011 10:52 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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 it goes something like this:

>> a
??? Undefined function or variable 'a'.

>> idx_new = [ 1 ; 2 ; 3];
>> size(idx_new)

ans =

3 1

>> = ones(6,1);
>> size(

ans =

6 1

>> par.height = 10.5;
>> par.height(

ans =


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.

There may be a good (almost very good reason) to do this, but for me
it came unexpected...

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.