Matrix replication column

John W. Eaton jwe at bevo.che.wisc.edu
Fri Apr 4 14:42:53 CDT 2008


On  4-Apr-2008, Oscar Bayona Candel wrote:

| 
| Hi all,
|  
| I´m using 
|  
| Z=repmat(1:B,M,1)
|  
| so it brings me a matrix whose size is (M,B) incrising each row in one unit
|  
| I want to create a new matrix 
|  
| GG whose size will be (M,H*B) 
|  
| The first H colums of GG will be the first column of Z, repeated H times. The second  H columns of GG will be the sencond columns of Z repeated.
|  
| An example:
|  
| B=3
| M=2
| H=3
|  
| so
|  
|  
| Z=[1 2 3
| 1 2 3];
|  
| The code I want to construct will have a result like this....
|  
| GG=[1 1 1  2 2 2 3 3 3
| 1 1 1  2 2 2 3 3 3];
|  
| I have been trying with kronecker function but I am not able...do
| you know some function similar.

Try

  B = 3;
  M = 2;
  H = 3;
  Z = repmat (1:B, M, 1)
  GG = kron (Z, ones (1, 3))

jwe



More information about the Help-octave mailing list