Thread Subject: Copying rows of numbers

Subject: Copying rows of numbers

From: Phil

Date: 12 Aug, 2009 10:17:04

Message: 1 of 4

Hello,

If i have the following:

ans = 2 6 8 10 4 12 7 8

which is a 1x8 matrix

How can i copy the row of numbers so i have the following:

ans = 2 6 8 10 4 12 7 8
         2 6 8 10 4 12 7 8
         2 6 8 10 4 12 7 8
         2 6 8 10 4 12 7 8

i.e. i would like to copy the 1x8 matrix to make a 4x8 matrix with the numbers in rows 2,3 and 4 the same as the ones in row 1.

Any help would be great.

Thanks,

Phil

Subject: Copying rows of numbers

From: Branko

Date: 12 Aug, 2009 10:38:04

Message: 2 of 4

"Phil " <harsh_classic@yahoo.co.uk> wrote in message <h5u4r0$rel$1@fred.mathworks.com>...
> Hello,
>
> If i have the following:
>
> ans = 2 6 8 10 4 12 7 8
>
> which is a 1x8 matrix
>
> How can i copy the row of numbers so i have the following:
>
> ans = 2 6 8 10 4 12 7 8
> 2 6 8 10 4 12 7 8
> 2 6 8 10 4 12 7 8
> 2 6 8 10 4 12 7 8
>
> i.e. i would like to copy the 1x8 matrix to make a 4x8 matrix with the numbers in rows 2,3 and 4 the same as the ones in row 1.
>
> Any help would be great.
>
> Thanks,
>
> Phil

Use repmat:

A=[2 6 8 10 4 12 7 8];
B=repmat(A,4,1);

Branko

Subject: Copying rows of numbers

From: us

Date: 12 Aug, 2009 12:51:04

Message: 3 of 4

"Phil " <harsh_classic@yahoo.co.uk> wrote in message <h5u4r0$rel$1@fred.mathworks.com>...
> Hello,
>
> If i have the following:
>
> ans = 2 6 8 10 4 12 7 8
>
> which is a 1x8 matrix
>
> How can i copy the row of numbers so i have the following:
>
> ans = 2 6 8 10 4 12 7 8
> 2 6 8 10 4 12 7 8
> 2 6 8 10 4 12 7 8
> 2 6 8 10 4 12 7 8
>
> i.e. i would like to copy the 1x8 matrix to make a 4x8 matrix with the numbers in rows 2,3 and 4 the same as the ones in row 1.
>
> Any help would be great.
>
> Thanks,
>
> Phil

one of the many solutions

     v=1:6;
     m=v(ones(4,1),:)
%{
     1 2 3 4 5 6
     1 2 3 4 5 6
     1 2 3 4 5 6
     1 2 3 4 5 6
%}

us

Subject: Copying rows of numbers

From: Phil

Date: 12 Aug, 2009 15:28:20

Message: 4 of 4

Brilliant.

Thanks,

Phil

"Branko " <bogunovic@mbss.org> wrote in message <h5u62c$g69$1@fred.mathworks.com>...
> "Phil " <harsh_classic@yahoo.co.uk> wrote in message <h5u4r0$rel$1@fred.mathworks.com>...
> > Hello,
> >
> > If i have the following:
> >
> > ans = 2 6 8 10 4 12 7 8
> >
> > which is a 1x8 matrix
> >
> > How can i copy the row of numbers so i have the following:
> >
> > ans = 2 6 8 10 4 12 7 8
> > 2 6 8 10 4 12 7 8
> > 2 6 8 10 4 12 7 8
> > 2 6 8 10 4 12 7 8
> >
> > i.e. i would like to copy the 1x8 matrix to make a 4x8 matrix with the numbers in rows 2,3 and 4 the same as the ones in row 1.
> >
> > Any help would be great.
> >
> > Thanks,
> >
> > Phil
>
> Use repmat:
>
> A=[2 6 8 10 4 12 7 8];
> B=repmat(A,4,1);
>
> Branko

Tags for this Thread

Everyone's Tags:

Add a New Tag:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
ones us 12 Aug, 2009 08:54:06
code us 12 Aug, 2009 08:54:06
repmat Branko 12 Aug, 2009 06:39:23
rssFeed for this Thread

Contact us at files@mathworks.com