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: How to copy a sub-matrix/vector along diagonal of a larger matrix ?
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Clutch

Posts: 8
Registered: 2/19/12
How to copy a sub-matrix/vector along diagonal of a larger matrix ?
Posted: Mar 8, 2013 8:16 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I want to create a matrix below where I copy A = [1 2 3] allow the diagonal of a matrix.

[ 1 2 3 0 0 0 0 0 0 0 0 0

0 0 1 2 3 0 0 0 0 0 0 0

0 0 0 0 0 0 1 2 3 0 0 0

0 0 0 0 0 0 0 0 0 1 2 3]

I know I can use blkdiag(A ,A, A, A) which will do the job however the number of parameters vary in my code. Sometimes, there may be five A vectors or 20 A vectors that I need to create such a matrix. Let's say this is a variable that the user inputs

How can I do this efficiently in code?



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.