Search All of the Math Forum:

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

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

Topic: compose matrix
Replies: 5   Last Post: Jul 27, 2013 3:48 AM

 Messages: [ Previous | Next ]
 Roger Stafford Posts: 5,929 Registered: 12/7/04
Re: compose matrix
Posted: Jul 27, 2013 3:48 AM

"eziwarman" wrote in message <kscmgr\$enp\$1@newscl01ah.mathworks.com>...
> say you have the matrix (1x4)
> u=[0 -5 0 5 0]
> and construct the matrix into (4x10)
> y=[0 -5 0 5 0 0 0 0 0 0;...
> 0 0 0 -5 0 5 0 0 0 0;...
> 0 0 0 0 0 -5 0 5 0 0;...
> 0 0 0 0 0 0 0 -5 0 5];

- - - - - - - - - -
This can be done in one line. Let u be the given row vector, r be the number of desired rows in y, and f be the offset between rows. In your example you have u = [0,-5,0,5], r = 4, and f = 2.

y = reshape([u';repmat([zeros(f*r,1);u'],r-1,1)],[],r)';

Roger Stafford

Date Subject Author
7/20/13 eziwarman
7/20/13 Nasser Abbasi
7/26/13 eziwarman
7/27/13 Roger Stafford