From: Hermano Cappa on 30 Mar 2010 07:48 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
From: kinor on 30 Mar 2010 08:01 "Hermano Cappa" <cappasteven(a)gmail.com> wrote in message <hosodj$k6q$1(a)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
From: Hermano Cappa on 30 Mar 2010 12:12 "kinor " <kinor.removethiswithdot(a)gmx.de> wrote in message <hosp62$1s5$1(a)fred.mathworks.com>... > "Hermano Cappa" <cappasteven(a)gmail.com> wrote in message <hosodj$k6q$1(a)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!!
|
Pages: 1 Prev: 1 D Heat equation solving by Crank Nicolson method Next: Problem with refreshing figure |