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:
combine 2 vectors to form a matrix

Subject: combine 2 vectors to form a matrix

From: Jose Miguel

Date: 26 May, 2012 08:47:38

Message: 1 of 3

Dear Matlab users,

I have a row vector (540x1) and a second row vector (361x1). I need to combine each element of the first vector with each element of the second row vector to form the corresponding two column matrix (194937x2). The brackets contain the dimension of the arrays/matrix implied.

For example, if a=[4 5] and b=[1 6 9], the result would be, c=[4 1;4 6;4 9;5 1;5 6;5 9]

Thank you very much,
Jose

Subject: combine 2 vectors to form a matrix

From: Bruno Luong

Date: 26 May, 2012 09:02:38

Message: 2 of 3

"Jose Miguel " <josemijauregui@hotmail.com> wrote in message <jpq5ba$gqf$1@newscl01ah.mathworks.com>...
> Dear Matlab users,
>
> I have a row vector (540x1) and a second row vector (361x1). I need to combine each element of the first vector with each element of the second row vector to form the corresponding two column matrix (194937x2). The brackets contain the dimension of the arrays/matrix implied.
>
> For example, if a=[4 5] and b=[1 6 9], the result would be, c=[4 1;4 6;4 9;5 1;5 6;5 9]
>

[A B]=meshgrid(a,b);
c = [A(:) B(:)]

% Bruno

Subject: combine 2 vectors to form a matrix

From: Jose Miguel

Date: 28 May, 2012 11:37:07

Message: 3 of 3

Thank you very much Bruno!
It works perfectly,
Regards>

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