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: Making a square matrix from two vector
Replies: 22   Last Post: Mar 19, 2013 12:37 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 17,945
Registered: 12/7/04
Re: Making a square matrix from two vector
Posted: Feb 12, 2013 11:50 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"james bejon" <jamesbejon@yahoo.co.uk> wrote in message
> Bruno--I really like this bsxops stuff, and have started using it in some
> of my projects at work. In the process, I've realised something which (at
> least in my view) is rather odd (though is nothing to do with your
> functions), namely the result of:
> (1:10).' + 1:10
> % the right way: (1:10).' + (1:10)

This is intentional behavior.


Parentheses are at level 1 in the precedence order. Transpose is at level 2.
Addition is at level 5. The colon operator is at level 6. Therefore this:

(1:10).' + 1:10

computes (1:10) first (level 1 and level 6 inside the parentheses), then
transposes the result (level 2), then adds 1 to that result (level 5), then
uses that vector as the first input to the colon operator (level 6.) That
just takes the first element as documented on the reference page for COLON.


"If you specify nonscalar arrays, MATLAB interprets j:i:k as

This also explains why your "the right way" resolves the problem; both sets
of parentheses at level 1 are processed before the addition at level 5.

This is also why -8^(1/3) gives -2 instead of (1+sqrt(3)*1i) as people
expect and sometimes post about here; exponentiation [8^(1/3)] is at level 2
while unary minus [- (8^(1/3))] is at level 3. (-8)^(1/3) gives the complex

Steve Lord
To contact Technical Support use the Contact Us link on

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

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.