Replicating rows in a matrix

236 views
Skip to first unread message

ADG

unread,
Nov 20, 2008, 4:46:39 PM11/20/08
to The MATLAB users
Hello everyone,

I am trying to replicate rows in a matrix as follows.

Base matrix, A = [0 0;0 1;1 1]
Another array specifies the multiples by which each row needs to
replicate.
Rep = [2 3 1]

Now, I am trying to look for some kind of expression that would lead
to the following answer:
OPERATION(A,Rep) ------> [0 0;0 0;0 1;0 1;0 1;1 1]

As shown in the example, each row is duplicated by the factor present
in the Rep array. Also, I am trying to perform this without using a
loop. Is this possible to do in matlab? I do not have a problem using
new data structures while achieving this. My only concern is to
achieve this without using a loop and repmat does not let you do this
operation.

Any/all response(s) is/are greatly appreciated!

Nikolay Dobrinov

unread,
Nov 20, 2008, 5:24:10 PM11/20/08
to matlab...@googlegroups.com
Hi,

what you can use is the function 'repmat'. Please go to help menu on matlab to see how it works. What you can do is take the first row and create a matrix where the first row is repeated as many times as you want(using repmat). Then do the same for the other 2 rows. You will end up with 3 matrices which you can vertically concatenate at the end to get your [0 0;0 0;0 1;0 1;0 1;1 1] matrix.

hope this helps
nick

2008/11/20 ADG <arju...@gmail.com>



--
Nikolay Dobrinov

University of Colorado, Boulder                              
nikolay....@colorado.edu
001 720 7715690
Reply all
Reply to author
Forward
0 new messages