# Thread Subject: rep rows of matrix

 Subject: rep rows of matrix From: Hans-Peter Suter Date: 13 Jan, 2003 02:52:52 Message: 1 of 4 Good morning, Is there some smart way to repeat the rows of a matrix according to a second vector that indicates how many times each row has to be copied. For example with A = [1990 5;1991 6] and B = [1 2]' I would get C = [1990 5;1991 6; 1991 6] Thank you for any ideas Hans-Peter
 Subject: rep rows of matrix From: JJ DeMann Date: 15 Jan, 2003 17:02:25 Message: 2 of 4 The think which is crossing my mind right now includes a damm loop. C=[]; for i = 1 : length(B)    C=[C;repmat(A(i,:),B(i),1)]; end -JJ- "Hans-Peter Suter" wrote in message news:eeb758b.-1@WebX.raydaftYaTP... > Good morning, > > > Is there some smart way to repeat the rows of a matrix according to a > second vector that indicates how many times each row has to be > copied. For example with A = [1990 5;1991 6] and B = [1 2]' I would > get > C = [1990 5;1991 6; 1991 6] > > > Thank you for any ideas > Hans-Peter
 Subject: rep rows of matrix From: Lucio Date: 15 Jan, 2003 17:33:48 Message: 3 of 4 If you matrix is large, the previous method may be slow, try this better... h=[]; h(cumsum(B))=1; C=A(cumsum(h)-h+1,:); Lucio
 Subject: rep rows of matrix From: Hans-Peter Suter Date: 16 Jan, 2003 05:55:33 Message: 4 of 4 > h=[]; > h(cumsum(B))=1; > C=A(cumsum(h)-h+1,:); wow, thanks. (Took me a while to digest...) Hans-Peter

Separated by commas
Ex.: root locus, bode

### What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.