Prev: SVDS inconsistency
Next: fitting model + plotting
From: sarrah on 8 May 2010 12:32 Hi, Let say I have a vector B=[1 0] and I want to use this vector B repeating in this matrix A having size [8x16]. First, I initialize the matrix A with all zeros then I want to have the outcome as below: A= [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0]; How can I use that vector B repeat several times on matrix A using some code? It looks like an eye matrix but the pattern is little bit different. I tried to do some looping but still doesn't get it as the above. Second question: I still want to use vector B to create another matrix C with size [4x8] as below and how to call it without constructing it manually? C= [1 0 0 0 0 0 0 0; 0 1 0 0 0 0 0 0; 0 0 0 0 1 0 0 0; 0 0 0 0 0 1 0 0]; Thanks in advance.
From: Mongkut Piantanakulchai on 8 May 2010 13:03 For the first one, try this B=[1 0]; A=blkdiag(B,B,B,B,B,B,B,B); Mongkut
From: sarrah on 9 May 2010 06:47 "Mongkut Piantanakulchai" <mongkutp.remove.this(a)gmail.com> wrote in message <hs45g9$rok$1(a)fred.mathworks.com>... > For the first one, try this > > B=[1 0]; > A=blkdiag(B,B,B,B,B,B,B,B); > > Mongkut Thanks Mongkut.It does help but I have to repeat the B for 8 times. Is there any other way for making it more flexible especially for larger size? I have other solution for question 1 by creating eye matrix of M size and then I want to remove all the even row. I knew we can delete row by specifying all the number of rows but it is restricted to smaller size of matrix. Instead of repeating the number of rows index, I want to make it flexible for greater size. Anybody please kindly share your ideas too. Many thanks.
From: John D'Errico on 9 May 2010 07:22 "sarrah " <gto_girlz83(a)yahoo.com> wrote in message <hs63r8$j9i$1(a)fred.mathworks.com>... > "Mongkut Piantanakulchai" <mongkutp.remove.this(a)gmail.com> wrote in message <hs45g9$rok$1(a)fred.mathworks.com>... > > For the first one, try this > > > > B=[1 0]; > > A=blkdiag(B,B,B,B,B,B,B,B); > > > > Mongkut > > Thanks Mongkut.It does help but I have to repeat the B for 8 times. Is there any other way for making it more flexible especially for larger size? > A = repmat({B},1,888); A = blkdiag(A{:}); Better yet is to make the result a sparse matrix. A = repmat({sparse(B)},1,888); A = blkdiag(A{:}); whos A Name Size Bytes Class Attributes A 888x1776 28424 double sparse John
From: sarrah on 9 May 2010 07:44
"John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <hs65sr$c9$1(a)fred.mathworks.com>... > "sarrah " <gto_girlz83(a)yahoo.com> wrote in message <hs63r8$j9i$1(a)fred.mathworks.com>... > > "Mongkut Piantanakulchai" <mongkutp.remove.this(a)gmail.com> wrote in message <hs45g9$rok$1(a)fred.mathworks.com>... > > > For the first one, try this > > > > > > B=[1 0]; > > > A=blkdiag(B,B,B,B,B,B,B,B); > > > > > > Mongkut > > > > Thanks Mongkut.It does help but I have to repeat the B for 8 times. Is there any other way for making it more flexible especially for larger size? > > > > A = repmat({B},1,888); > A = blkdiag(A{:}); > > Better yet is to make the result a sparse matrix. > > A = repmat({sparse(B)},1,888); > A = blkdiag(A{:}); > > whos A > Name Size Bytes Class Attributes > A 888x1776 28424 double sparse > > John ---------------------------------------- Thanks a lot John!! How about I still want to use the same vector B[1 0] creates this D matrix as below: D= [1 0 0 0 0 0 0 0; 0 1 0 0 0 0 0 0; 0 0 0 0 1 0 0 0; 0 0 0 0 0 1 0 0]; I don't think we can use the blkdiag function again. Any idea? |