Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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

>> net.bt = ones(6,1);
>> size(net.bt)


ans =

6 1

>> par.height = 10.5;
>> par.height(net.bt(idx_new))


ans =

10.5000
10.5000
10.5000

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.

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

Wishing a happy day,
Andreas



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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.