Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Interleaving three vectors

Subject: Interleaving three vectors

From: Adshak

Date: 23 Jan, 2009 01:02:15

Message: 1 of 4

Dear All,


I have three vectors of same size or dimensions,

Let us consider those three vectors all of same dimensions.

a = [1 1 1 1 1....];
b = [2 2 2 2 2.....];
c = [3 3 3 3 3...];

NOw ho dow I interleave these three vectors such as such that my
final vector is:

vectorfinal = [1 2 3 1 2 3 1 2 3.....] i.e this vector now is three
times the dimensions of the sample vectors.


Advanced thank you for all your help.

Adshak

Subject: Interleaving three vectors

From: Roger Stafford

Date: 23 Jan, 2009 01:26:02

Message: 2 of 4

Adshak <adshaikh.hipnet@googlemail.com> wrote in message <394b5a8f-5212-4560-8556-2fbe882fad6d@w24g2000prd.googlegroups.com>...
> Dear All,
>
>
> I have three vectors of same size or dimensions,
>
> Let us consider those three vectors all of same dimensions.
>
> a = [1 1 1 1 1....];
> b = [2 2 2 2 2.....];
> c = [3 3 3 3 3...];
>
> NOw ho dow I interleave these three vectors such as such that my
> final vector is:
>
> vectorfinal = [1 2 3 1 2 3 1 2 3.....] i.e this vector now is three
> times the dimensions of the sample vectors.
>
>
> Advanced thank you for all your help.
>
> Adshak

 vectorfinal = reshape([a;b;c],1,[]);

Roger Stafford

Subject: Interleaving three vectors

From: Steven Lord

Date: 23 Jan, 2009 16:59:55

Message: 3 of 4


"Adshak" <adshaikh.hipnet@googlemail.com> wrote in message
news:394b5a8f-5212-4560-8556-2fbe882fad6d@w24g2000prd.googlegroups.com...
> Dear All,
>
>
> I have three vectors of same size or dimensions,
>
> Let us consider those three vectors all of same dimensions.
>
> a = [1 1 1 1 1....];
> b = [2 2 2 2 2.....];
> c = [3 3 3 3 3...];
>
> NOw ho dow I interleave these three vectors such as such that my
> final vector is:
>
> vectorfinal = [1 2 3 1 2 3 1 2 3.....] i.e this vector now is three
> times the dimensions of the sample vectors.
>
>
> Advanced thank you for all your help.

Roger's given you the RESHAPE method. Another method is to use indexing.

d = zeros(1, numel(a)+numel(b)+numel(c));
d(1:3:end) = a;
d(2:3:end) = b;
d(3:3:end) = c;

--
Steve Lord
slord@mathworks.com

Subject: Interleaving three vectors

From: Adshak

Date: 27 Jan, 2009 21:32:44

Message: 4 of 4

On Jan 23, 4:59=A0pm, "Steven Lord" <sl...@mathworks.com> wrote:
> "Adshak" <adshaikh.hip...@googlemail.com> wrote in message
>
> news:394b5a8f-5212-4560-8556-2fbe882fad6d@w24g2000prd.googlegroups.com...
>
>
>
>
>
> > Dear All,
>
> > I have three vectors of same size or dimensions,
>
> > Let us consider those three vectors all of same dimensions.
>
> > a =3D [1 1 1 1 1....];
> > b =3D [2 2 2 2 2.....];
> > c =3D [3 3 3 3 3...];
>
> > NOw ho dow I interleave these three vectors such as =A0such that my
> > final vector is:
>
> > vectorfinal =3D [1 2 3 1 2 3 1 2 3.....] =A0i.e this vector now is thre=
e
> > times the dimensions of the sample vectors.
>
> > Advanced thank you for all your help.
>
> Roger's given you the RESHAPE method. =A0Another method is to use indexin=
g.
>
> d =3D zeros(1, numel(a)+numel(b)+numel(c));
> d(1:3:end) =3D a;
> d(2:3:end) =3D b;
> d(3:3:end) =3D c;
>
> --
> Steve Lord
> sl...@mathworks.com- Hide quoted text -
>
> - Show quoted text -

Thank you both so much...

It worked just fine.

Tags for this Thread

No tags are associated with this thread.

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.

Contact us