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:
simple matrix operation

Subject: simple matrix operation

From: Hermano Cappa

Date: 30 Mar, 2010 11:48:03

Message: 1 of 3

Hi,

I want to write a easy method for a simple matrix operation but I don't know how to start.

I have two matrices A and B:

A = [0 0.5; 1 1.5; 2 2.5]; % number of rows can change, columns is 2
B = [10; 20]; % 2 x 1 matrix

I want combine them to a matrix C with the result:

C = [0 10; 0.5 20; 1 10; 1.5 20; 2 10; 2.5 20];

How can I do this?

Thanks

Subject: simple matrix operation

From: kinor

Date: 30 Mar, 2010 12:01:06

Message: 2 of 3

"Hermano Cappa" <cappasteven@gmail.com> wrote in message <hosodj$k6q$1@fred.mathworks.com>...
> Hi,
>
> I want to write a easy method for a simple matrix operation but I don't know how to start.
>
> I have two matrices A and B:
>
> A = [0 0.5; 1 1.5; 2 2.5]; % number of rows can change, columns is 2
> B = [10; 20]; % 2 x 1 matrix
>
> I want combine them to a matrix C with the result:
>
> C = [0 10; 0.5 20; 1 10; 1.5 20; 2 10; 2.5 20];
>
> How can I do this?
>
> Thanks

Hi Hermano,

one of many ways:
a = A';
a = a(:);
b = repmat(B, [length(a)/2 1])
C = [a b]

hth
kinor

Subject: simple matrix operation

From: Hermano Cappa

Date: 30 Mar, 2010 16:12:05

Message: 3 of 3

"kinor " <kinor.removethiswithdot@gmx.de> wrote in message <hosp62$1s5$1@fred.mathworks.com>...
> "Hermano Cappa" <cappasteven@gmail.com> wrote in message <hosodj$k6q$1@fred.mathworks.com>...
> > Hi,
> >
> > I want to write a easy method for a simple matrix operation but I don't know how to start.
> >
> > I have two matrices A and B:
> >
> > A = [0 0.5; 1 1.5; 2 2.5]; % number of rows can change, columns is 2
> > B = [10; 20]; % 2 x 1 matrix
> >
> > I want combine them to a matrix C with the result:
> >
> > C = [0 10; 0.5 20; 1 10; 1.5 20; 2 10; 2.5 20];
> >
> > How can I do this?
> >
> > Thanks
>
> Hi Hermano,
>
> one of many ways:
> a = A';
> a = a(:);
> b = repmat(B, [length(a)/2 1])
> C = [a b]
>
> hth
> kinor

Thank you very much Kinor!!

Tags for 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