# Thread Subject: create matrix of vectors

 Subject: create matrix of vectors From: arron lacey Date: 22 Jun, 2012 07:39:09 Message: 1 of 8 Hi, i have two matrices: a = 1 2 3 4 5 6 7 8 9 b = 9 8 7 6 5 4 3 2 1 i want to create a matrix of vectors using the logic element1 = [a(1,1) b(1,1) 0] and so on.... in fact i would like to extend the problem to two nxn matrices while appending the z dimension. How would I go about populating such a matrix?
 Subject: create matrix of vectors From: Matt J Date: 22 Jun, 2012 08:05:09 Message: 2 of 8 "arron lacey" wrote in message ... > Hi, i have two matrices: > > a = > > 1 2 3 > 4 5 6 > 7 8 9 > > b = > > 9 8 7 > 6 5 4 > 3 2 1 > > i want to create a matrix of vectors using the logic > > element1 = [a(1,1) b(1,1) 0] > > and so on.... in fact i would like to extend the problem to two nxn matrices while appending the z dimension. How would I go about populating such a matrix? When you say a "matrix of vectors", I assume you mean a cell array. If so, then do as below. Otherwise, it's not clear what you mean. The elements of a "matrix" are scalars by definition. C=num2cell([a(:),b(:),zeros(size(b(:)))],2); C=reshape(C,size(b));
 Subject: create matrix of vectors From: Nasser M. Abbasi Date: 22 Jun, 2012 08:06:22 Message: 3 of 8 On 6/22/2012 2:39 AM, arron lacey wrote: > Hi, i have two matrices: > > a = > > 1 2 3 > 4 5 6 > 7 8 9 > > b = > > 9 8 7 > 6 5 4 > 3 2 1 > > i want to create a matrix of vectors using the logic > > element1 = [a(1,1) b(1,1) 0] > > and so on.... in fact i would like to extend the problem to two nxn matrices while appending the z dimension. How would I go about populating such a matrix? > hard to understand. may be this is what you want. Try to write a more complete output example. EDU>> N=3 a = [1 2 3;       4 5 6;       7 8 9]; b = [9 8 7;       6 5 4;       3 2 1] C=[a(:) b(:) zeros(N^2,1)] C =       1 9 0       4 6 0       7 3 0       2 8 0       5 5 0       8 2 0       3 7 0       6 4 0       9 1 0 --Nasser
 Subject: create matrix of vectors From: arron lacey Date: 22 Jun, 2012 10:24:07 Message: 4 of 8 "Nasser M. Abbasi" wrote in message ... > On 6/22/2012 2:39 AM, arron lacey wrote: > > Hi, i have two matrices: > > > > a = > > > > 1 2 3 > > 4 5 6 > > 7 8 9 > > > > b = > > > > 9 8 7 > > 6 5 4 > > 3 2 1 > > > > i want to create a matrix of vectors using the logic > > > > element1 = [a(1,1) b(1,1) 0] > > > > and so on.... in fact i would like to extend the problem to two nxn matrices while appending the z dimension. How would I go about populating such a matrix? > > > > hard to understand. may be this is what you want. Try to write > a more complete output example. > > EDU>> N=3 > a = [1 2 3; > 4 5 6; > 7 8 9]; > > b = [9 8 7; > 6 5 4; > 3 2 1] > > C=[a(:) b(:) zeros(N^2,1)] > > C = > 1 9 0 > 4 6 0 > 7 3 0 > 2 8 0 > 5 5 0 > 8 2 0 > 3 7 0 > 6 4 0 > 9 1 0 > > > --Nasser Thanks very much for the reply. It is interesting to here that the element of a matrix can only be a scalar. Ideally what I want is to be able to read in two arrays of any size (although both the same size) and then create a matrix, or cell array which holds something like: cellarray = [a(1,1) b(1,1) 0] [a(1,2) b(1,2) 0] [a(1,3) b(1,3) 0] ........... [a(1,n) b(1,n) 0] [a(2,1) b(2,1) 0] [a(2,2) b(2,2) 0] [a(2,3) b(2,3) 0] [a(3,1) b(3,1) 0] [a(3,2) b(3,2) 0] [a(3,3) b(3,3) 0] . . . [a(n,1) b(n,1) 0] does that make it a bit clearer? that means that i can use each element in a cross product with another cell array constructed in a similar way.
 Subject: create matrix of vectors From: arron lacey Date: 22 Jun, 2012 10:47:07 Message: 5 of 8 also if I do: C=[a(:) b(:) zeros(N^2,1)] i get size(C(1,1)) = 1 1 but i actually need the size of each element to be 1 3 so i can use it in a cross product. i.e. if i do: C = [A(1,1) B(1,1)] I get size(C) = 1 3 so the dimensions are correct.
 Subject: create matrix of vectors From: Matt J Date: 22 Jun, 2012 12:01:09 Message: 6 of 8 "arron lacey" wrote in message ... > > cellarray = > > [a(1,1) b(1,1) 0] [a(1,2) b(1,2) 0] [a(1,3) b(1,3) 0] ........... [a(1,n) b(1,n) 0] > [a(2,1) b(2,1) 0] [a(2,2) b(2,2) 0] [a(2,3) b(2,3) 0] > [a(3,1) b(3,1) 0] [a(3,2) b(3,2) 0] [a(3,3) b(3,3) 0] > . > . > . > [a(n,1) b(n,1) 0] > > > does that make it a bit clearer? that means that i can use each element in a cross product with another cell array constructed in a similar way. ================== That does make it clearer, but it's what I already gave you in my previous post.
 Subject: create matrix of vectors From: arron lacey Date: 22 Jun, 2012 13:14:08 Message: 7 of 8 > > That does make it clearer, but it's what I already gave you in my previous post. HI Matt yes - sorry, I was replying to the last reply which was Nasser's, was going to reply to yours but got called into a meeting. Yes the way you have done it is exactly what I am looking for. thanks very much.
 Subject: create matrix of vectors From: Steven_Lord Date: 22 Jun, 2012 13:29:10 Message: 8 of 8 "arron lacey" wrote in message news:js1ifb\$3rq\$1@newscl01ah.mathworks.com... > also if I do: > > C=[a(:) b(:) zeros(N^2,1)] > > i get > size(C(1,1)) = > > 1 1 > > but i actually need the size of each element to be 1 3 so i can use it in > a cross product. Take a look at C(1, :). That extracts one whole row of C, and by the way C's been constructed that row is 1-by-3. -- Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com

### Everyone's Tags:

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.