f



Creating a J*J Diagonal Matrix with Jth Diagonal element is also a matrix

Hello,

I am a new beginner of Matlab and I want to create a Diagnoal Matrix with the main diagnoal as (A1,A2,A3,....,Aj) where Aj is also a matrix which is defined as (a11,a12,a13;a21,a22,a23;a31,a32,a33). How can I define Aj as a variable in the m file then create the diagnoal matrix through Aj?

Could someone help on this please? Many Thanks in Advance! 
0
jz286 (28)
8/23/2009 10:09:02 PM
comp.soft-sys.matlab 211266 articles. 19 followers. lunamoonmoon (257) is leader. Post Follow

7 Replies
392 Views

Similar Articles

[PageSpeed] 52

"Jie " <jz286@cam.ac.uk> wrote in message <h6selu$9ng$1@fred.mathworks.com>...
> Hello,
> 
> I am a new beginner of Matlab and I want to create a Diagnoal Matrix with the main diagnoal as (A1,A2,A3,....,Aj) where Aj is also a matrix which is defined as (a11,a12,a13;a21,a22,a23;a31,a32,a33). How can I define Aj as a variable in the m file then create the diagnoal matrix through Aj?
> 
> Could someone help on this please? Many Thanks in Advance! 

help blkdiag

John
0
woodchips (7944)
8/23/2009 11:16:04 PM
Hi John,

Many thanks for this. What if I have more than 100 on J, it is not very convinient to use blkdiag and I also have different matrix for each Aj. Is there a loop that I can do?
Many Thanks.

Jie
0
jz286 (28)
8/23/2009 11:35:02 PM
"Jie " <jz286@cam.ac.uk> wrote in message <h6sjn6$3nb$1@fred.mathworks.com>...
> Hi John,
> 
> Many thanks for this. What if I have more than 100 on J, it is not very convinient to use blkdiag and I also have different matrix for each Aj. Is there a loop that I can do?
> Many Thanks.
> 
> Jie

DON'T store the matrices in separate arrays.

DO use a single cell array.

Finally, learn how to turn a cell array into a
comma separated list.

blkdiag(A{:})

john
0
woodchips (7944)
8/24/2009 12:32:01 AM
John,

Many Thanks for your help on this. I wrote the code below which will do the same trick

function test3()
C=cell(148,148);
M=[1,1,1,1,1;2,2,2,2,2;3,3,3,3,3;4,4,4,4,4;5,5,5,5,5];
N=zeros(5,5);
for i=1:100
    for j=1:100
     if i==j
     C{i,j}=M;
     else
     C{i,j}=N;                 
     end
    end
end
D=cell2mat(C);
save D D
end

Now my question is that if it is possible to have sth like
D=cell2mat(C{i,j}) so that I can convert an element of the cell into a matrix?

Many Thanks

Jie
0
jz286 (28)
8/24/2009 7:19:03 PM
"Jie " <jz286@cam.ac.uk> wrote in message <h6up37$sse$1@fred.mathworks.com>...
> John,
> 
> Many Thanks for your help on this. I wrote the code below which will do the same trick
> 
> function test3()
> C=cell(148,148);
> M=[1,1,1,1,1;2,2,2,2,2;3,3,3,3,3;4,4,4,4,4;5,5,5,5,5];
> N=zeros(5,5);
> for i=1:100
>     for j=1:100
>      if i==j
>      C{i,j}=M;
>      else
>      C{i,j}=N;                 
>      end
>     end
> end
> D=cell2mat(C);
> save D D
> end
> 
> Now my question is that if it is possible to have sth like
> D=cell2mat(C{i,j}) so that I can convert an element of the cell into a matrix?
> 
> Many Thanks
> 
> Jie

I'm confused by your question, since this is NOT even
remotely what I was suggesting that you do. Read
my last response.

You wanted to create a block diagonal matrix. Do
this:

M = rand(5);
C = repmat({M},1,10);
A = blkdiag(C{:});
spy(A)

You may find some useful ideas for even more
effectively creating block diagonal matrices in my
blktridiag, found on the file exchange.

http://www.mathworks.com/matlabcentral/fileexchange/10603

John
0
woodchips (7944)
8/24/2009 7:50:19 PM
Hi John,

I found this would do

D=[C{i,j}];

Thanks all the same.

Jie
0
jz286 (28)
8/24/2009 8:12:04 PM
"Jie " <jz286@cam.ac.uk> wrote in message <h6us6k$m6d$1@fred.mathworks.com>...
> Hi John,
> 
> I found this would do
> 
> D=[C{i,j}];
> 
> Thanks all the same.
> 
> Jie

but this is very different from what you wanted initially...

us
0
us1 (8051)
8/24/2009 9:46:02 PM
Reply:

Similar Artilces:

add column matrix to each element of each diagonal in square matrix
A(mxm) square (where m is odd from 3 to 99) E(1xn) (where n is the number of diagonals of A) i need to add each element of E to each element of the corresponding diagonal of A Result is B(mxm) 1st diagonal B(1,1)=A(1,1)+E(1,1); 2nd diagonal B(2,1)=A(2,1)+E(1,2); B(1,2)=A(1,2)+E(1,2); 3rd diagonal B(3,1)=A(3,1)+E(1,3); B(2,2)=A(2,2)+E(1,3); B(1,3)=A(1,3)+E(1,3); and so on ... nth diagonal B(m,m)=A(m,m)+E(1,n); I kind of got stick below. Appreciate help with finishing this or a new solution. For example when m=5; n=9; A=[1 2 3 4 5; 2 3 1 0 0; 1 1 2 3 5; 0 1 2 2 2; 3 3 1 1 1]; E=[1 -1 0 3 2 -4 6 -4 1]; [Dia, no] =spdiags(flipud(A)); for i=1:n newDia(:,i)=Dia(:,i)+E(1,i); end Answer B s hould be 5x5 Thank you very much Z=flipud(toeplitz(E(end:-1:1))); B=A+Z(1:m,1:m); "Matt J" wrote in message <jabdfj$k16$1@newscl01ah.mathworks.com>... > Z=flipud(toeplitz(E(end:-1:1))); > B=A+Z(1:m,1:m); - - - - - - - - - - Also you can use the 'hankel' function and avoid doing the flip: B = A + hankel(E(1:m),E(m:2*m-1)); Roger Stafford "Matt J" wrote in message <jabdfj$k16$1@newscl01ah.mathworks.com>... > > Z=flipud(toeplitz(E(end:-1:1))); > B=A+Z(1:m,1:m); Thank you "Roger Stafford" wrote in message <jabhge$40c$1@newscl01ah.mathworks.com>... > "Matt J" wrote in message <jabdfj$k16$1@newscl01ah.mathworks.com>... > > Z=flipud(t...

Re: Symmetric matrix elements below the diagonal elements
--- Stefan Pohl <stefan.pohl@ISH.DE> wrote: > Hi SAS-group, > > I have a symmetric matrix with zero diagonal elements. This is a > small > example > > id var1 var2 var3 var4 > 1 0 1 2 1 > 2 1 0 5 4 > 3 2 5 0 3 > 4 1 4 3 0 > > I want to get a new variable with the elements below the 0 diagonal > elements, i.e. > > varnew > 1 > 2 > 1 > 5 > 4 > 3 > > How can I do this? > > Thank you for any help. > > Stefan. > Stefan, If you want the values in the order that you show above, then the key to obtaining a simple solution is to write out the values above the diagonal. If var1-var4 are named to an array, then all we need to do is loop over array elements from the diagonal position plus 1 through the fourth array element. The diagonal position is obtained from the data row _n_. We output the values that we loop over. data sym_mat; input id var1 var2 var3 var4; cards; 1 0 1 2 1 2 1 0 5 4 3 2 5 0 3 4 1 4 3 0 ; data up_part; set sym_mat; array var {4}; do i=_n_+1 to 4; y = var{i}; output; end; keep y; run; proc print; run; HTH, Dale --------------------------------------- Dale McLerran Fred Hutchinson Cancer Research Center mailto: dmclerra@NO_SPAMfhcrc.org Ph: (206) 667-2926 Fax: (206) 667-5977 --------------------------------------- ________________________________...

Select matrix elements above diagonal
Is there a function which I can use to easily select the matrix element above or under the diagonal (and optionally including the diagonal)? I've written a loop to do this, but it would make sense to me if there is a more easy way. Thanks "Joey" wrote in message <j3ntbm$o3d$1@newscl01ah.mathworks.com>... > Is there a function which I can use to easily select the matrix element above or under the diagonal (and optionally including the diagonal)? I've written a loop to do this, but it would make sense to me if there is a more easy way. > > Thanks doc tril doc triu James Tursa "James Tursa" wrote in message <j3o1dj$936$1@newscl01ah.mathworks.com>... > "Joey" wrote in message <j3ntbm$o3d$1@newscl01ah.mathworks.com>... > > Is there a function which I can use to easily select the matrix element above or under the diagonal (and optionally including the diagonal)? I've written a loop to do this, but it would make sense to me if there is a more easy way. > > > > Thanks > > doc tril > doc triu Are you interested in *all* of the elements above or below the diagonal, or only the ones immediately next to the diagonal? James Tursa ...

sparse matrix 3 diagonals and 3 elements
Hello, i need to create a sparse matrix with 3 diagonals. Each diagonal stores only one element. My matrix looks like this: | a 0 . 0 b 0 . 0 c 0 . 0| | 0 a . 0 0 b . 0 0 c . 0| | . . . 0 . . . . 0 . . . 0| | 0 0 0 a 0 0 0 b 0 0 0 c| i found a function called spdiags and stuck with it. can anyone help please? "wma " <wma@wma.test> wrote in message <hjpkqo$3io$1@fred.mathworks.com>... > Hello, > > i need to create a sparse matrix with 3 diagonals. Each diagonal stores only one element. > > My matrix looks like this: > | a 0 . 0 b 0 . 0 c 0 . 0| > | 0 a . 0 0 b . 0 0 c . 0| > | . . . 0 . . . . 0 . . . 0| > | 0 0 0 a 0 0 0 b 0 0 0 c| > > i found a function called spdiags and stuck with it. > > can anyone help please? You can simple concatenate the individual diagonal sparse matrices. Here is an example: A = 10 ; B = 20 ; Siz = 4 ; s1 = spdiags(repmat(A,Siz,1),0,Siz,Siz) s2 = spdiags(repmat(B,Siz,1),0,Siz,Siz) result = [s1 s2] full(result) % nicer display hth Jos > You can simple concatenate the individual diagonal sparse matrices. Here is an example: > > A = 10 ; B = 20 ; > Siz = 4 ; > > s1 = spdiags(repmat(A,Siz,1),0,Siz,Siz) > s2 = spdiags(repmat(B,Siz,1),0,Siz,Siz) > result = [s1 s2] > full(result) % nicer display > > hth > Jos Thank you for the big help! "wma " <wma@wma.test> wrote in message <hjpkqo$3io$1@fred.mathworks.com...

What is the matLAB code for creating a sub matrix from by selecting every nth element from a vector
Dear global users of MATLAB I am a new user of MATLAB, I will be glad to be guided on how to create another submatrix (i, j) by selecting every nth element (m x n) from a matrix On Mar 5, 10:58=A0pm, "Akeem Wale" <abu...@gmail.com> wrote: > Dear global users of MATLAB > > I am a new user of MATLAB, I will be glad to be guided on how to create a= nother > submatrix (i, j) by selecting every nth element (m x n) from a matrix ---------------------------------------------------------------------------= ---------------- submatrix =3D fullmatrix(startingRow:n:end, startingColumn:n:end); ...

Comparing elements of a matrix with a threshold matrix
Hi, Given a matrix A = 1 1 2 2 1 1 3 0 3 and B is a row vector containing threshold values corresponding to each column of matrix A, where B = 3.5000 1.0000 3.5000 I am trying to compare each row element in A with the corresponding row elements in B such that if and row element in A >= a row element in B, then result = 1, else result = 0. The resulting matrix I am looking for here should be a matrix C = 0 1 0 0 1 0 0 0 0 Any assistance is appreciated. -jojo On Jun 14, 2:40=A0pm, "Josephine " <jo...@umbc.edu> wrote: > Hi, > Given a matrix =A0 > A =3D =A0 =A0 1 =A0 =A0 1 =A0 =A0 2 > =A0 =A0 =A0 =A0 =A0 2 =A0 =A0 1 =A0 =A0 1 > =A0 =A0 =A0 =A0 =A0 3 =A0 =A0 0 =A0 =A0 3 > and B is a row vector containing threshold values corresponding to each c= olumn of matrix A, where B =3D =A03.5000 =A0 =A01.0000 =A0 =A03.5000 > > I am trying to compare each row element in A with the corresponding row e= lements in B such that if and row element in A >=3D a row element in B, the= n result =3D 1, else result =3D 0. > The resulting matrix I am looking for here should be a matrix C =3D > 0 =A0 =A0 =A0 1 =A0 =A0 =A0 0 > 0 =A0 =A0 =A0 1 =A0 =A0 =A0 0 > 0 =A0 =A0 =A0 0 =A0 =A0 =A0 0 > > Any assistance is appreciated. > -jojo Here's one way: n=3Dsize(A,1); M=3Dones(n,1)*B; % Make a comparison matrix C=3DA>=3DM; "Josephine " <jona1@umbc.edu> wrote in m...

Diagonal Gaussian Matrix
Dear all, I would like to create a diagonal matrix in matlab where the diagonal instead of ones will contain numbers coming from a gaussian distribution. could you please help me with that ? Regards Alex On 2/9/2012 10:57 AM, Alex wrote: > Dear all, > I would like to create a diagonal matrix in matlab where the diagonal > instead of ones will contain numbers coming from a gaussian distribution. .... doc diag doc randn -- dpb <none@non.net> wrote in message <jh1142$3qr$1@speranza.aioe.org>... > On 2/9/2012 10:57 AM, Alex wrote: > > Dear all, > > I would like to create a diagonal matrix in matlab where the diagonal > > instead of ones will contain numbers coming from a gaussian distribution. > ... > > doc diag > doc randn > > -- and how to insert in the diag the elements of randn? "Alex " <alaios@yahoo.com> wrote in message news:jh11n3$2h9$1@newscl01ah.mathworks.com... > dpb <none@non.net> wrote in message <jh1142$3qr$1@speranza.aioe.org>... >> On 2/9/2012 10:57 AM, Alex wrote: >> > Dear all, >> > I would like to create a diagonal matrix in matlab where the diagonal >> > instead of ones will contain numbers coming from a gaussian >> > distribution. >> ... >> >> doc diag >> doc randn >> >> -- > and how to insert in the diag the elements of randn? As the v input to DIAG. http://www.mathwork...

About the element of Matrix in Matlab
I have a difficulty in using Matlab to create a matrix. The matrix have its element is a random function of time-varying valuable t such as Gaussian or Sin. When t changes the matrix is changed and my system will use this matrix to calculate. My example: A is a square matrix 3,3. A(1,1) = 2 sin(t), A(1,2)=1 sin(t), A(1,3)= 3cos(t). A(2,1) = 1 cos(t),A(2,2) = 3sin(t), A(2,3) = 2cos(t). A (3,1)= 0.5sin(t),A(3,2) = 1.5sin(t),A(3,3)=3sin(t). A will be changed when t is running. So how I can matrix A to calculate. Please help me about Matlab code. Thanks. "Viet Dang" <muaphongba@yahoo.com> wrote in message news:hc3956$el9$1@fred.mathworks.com... >I have a difficulty in using Matlab to create a matrix. The matrix have its >element is a random function of time-varying valuable t such as Gaussian >or Sin. When t changes the matrix is changed and my system will use this >matrix to calculate. > > My example: > > A is a square matrix 3,3. > > A(1,1) = 2 sin(t), A(1,2)=1 sin(t), A(1,3)= 3cos(t). > A(2,1) = 1 cos(t),A(2,2) = 3sin(t), A(2,3) = 2cos(t). > A (3,1)= 0.5sin(t),A(3,2) = 1.5sin(t),A(3,3)=3sin(t). > > A will be changed when t is running. So how I can matrix A to calculate. > Please help me about Matlab code. Thanks. syms t A=[2*sin(t) sin(t) 3*cos(t); cos(t) 3*sin(t) 2*cos(t); 0.5*sin(t) 5*sin(t) 3*sin(t)] EDU>> for time=1:3 subs(A,t,time) end 1.6829 0...

changing diagonal of a matrix
if I have a matrix A = [1, 2 ; 3, 4] I want its diagonal to be 2 & 2 instead of 1 & 4 how one can do that? "Samoline1 Linke" <maganatewoman@yahoo.com> wrote in message <hjp2lg$9do$1@fred.mathworks.com>... > if I have a matrix A = [1, 2 ; 3, 4] > > I want its diagonal to be 2 & 2 instead of 1 & 4 > > how one can do that? Something along these lines, perhaps? A = -magic(4) Q = eye(size(A))==1 A(Q) = 2 hth Jos "Jos (10584) " <#10584@fileexchange.com> wrote in message <hjp387$fum$1@fred.mathworks.com>... > "Samoline1 Linke" <maganatewoman@yahoo.com> wrote in message <hjp2lg$9do$1@fred.mathworks.com>... > > if I have a matrix A = [1, 2 ; 3, 4] > > > > I want its diagonal to be 2 & 2 instead of 1 & 4 > > > > how one can do that? > > Something along these lines, perhaps? > > A = -magic(4) > Q = eye(size(A))==1 > A(Q) = 2 > > hth > Jos ---- Thanks for the reply but this changes the off-diagonal values....I want to keep off-diagonal values same....Could you tell me how to do that as well? Thanks "Samoline1 Linke" <maganatewoman@yahoo.com> wrote in message <hjp3r1$n3m$1@fred.mathworks.com>... > "Jos (10584) " <#10584@fileexchange.com> wrote in message <hjp387$fum$1@fred.mathworks.com>... > > "Samoline1 Linke" <maganatewoman@yahoo.com> ...

About diagonally dominant matrix
hello people i would like to know how do i get my matrix into a diagonally dominant form, is there a certian script to re arrange my matrix? thank you "Abdullah " <lucker8@live.com> wrote in message <i8lti0$efs$1@fred.mathworks.com>... > hello people > > i would like to know how do i get my matrix into a diagonally dominant form, is there a certian script to re arrange my matrix? > > thank you - - - - - - - - - - What kinds of "rearrangements" do you have in mind? Multiplication on the left and right by unitary matrices as with singular value decomposition can certainly get you to a diagonally dominant form. In fact everything outside the diagonal disappears altogether in that case. Roger Stafford On 10/7/2010 6:53 PM, Abdullah wrote: > hello people > > i would like to know how do i get my matrix into a diagonally dominant form, is there a certian > script to re arrange my matrix? > > thank you May be there is a command to do this. But from definition: http://math.nist.gov/MatrixMarket/glossary.html "Diagonal Dominance A matrix is diagonally dominant if the absolute value of each diagonal element is greater than the sum of the absolute values of the other elements in its row (or column)" Then given a matrix A, you need to just find the max of each row's sum and and each column's sum, and replace the diagonal element by the corresponding maximum of the 2 ...

how to create a new matrix from a [n 1] matrix
Hi all, I have a nx1 matrix and i want to create an axb matrix from this lines by taking the first a columns and setting as column 1, taking next a columns and putting it right of the first a columns etc. An example to be more clear: data= a b c d e f g h i have 8x1 matrix and i need to get a 2x4 matrix from this like: a c e g b d f h Any advice to create such a matrix for a really big number of n? Thanks for all the replays! Burcu "burcu " <burcu102@hotmail.com> wrote in message <hdhfbn$m36$1@fred.mathworks.com>... > Hi all, > > I have a nx1 matrix and i want to create an axb matrix from this lines by taking the first a columns and setting as column 1, taking next a columns and putting it right of the first a columns etc. > An example to be more clear: > > data= a > b > c > d > e > f > g > h > i have 8x1 matrix and i need to get a 2x4 matrix from this like: > a c e g > b d f h > Any advice to create such a matrix for a really big number of n? > > Thanks for all the replays! > > Burcu Use reshape(data,2,4) See help reshape Thanks Dips, exactly what i want. Burcu "Dips Bhatia" <deepakdbhatia@gmail.com> wrote in message <hdhg0a$2ke$1@fred.mathworks.com>... > "burcu " <...

how to insert a matrix into a matrix
i know this might sound like a dumb question but.. i have a 5 by 1 matrix a=[1,2,3,4,5] i now have another matrix b say 5 by 5 matrix. i want a to insert matrix b into matrix a such that matrix a's 1st column still has the values 1,2,3,4,5 and the rest of the columns will have the values of matrix b. Thanks in advance "ashish mohan" wrote in message <jms2fr$sgd$1@newscl01ah.mathworks.com>... > i know this might sound like a dumb question but.. > i have a 5 by 1 matrix a=[1,2,3,4,5] > i now have another matrix b say 5 by 5 matrix. > i want a to insert matrix b into matrix a such that matrix a's 1st column still has the values > 1,2,3,4,5 and the rest of the columns will have the values of matrix b. > > Thanks in advance >> a = [1 2 3 4 5] a = 1 2 3 4 5 >> b = [11 12 13 14 15; 21 22 23 24 25; 31 32 33 34 35; 41 42 43 44 45; 51 52 53 54 55] b = 11 12 13 14 15 21 22 23 24 25 31 32 33 34 35 41 42 43 44 45 51 52 53 54 55 >> a(2:6,1:5) = b a = 1 2 3 4 5 11 12 13 14 15 21 22 23 24 25 31 32 33 34 35 41 42 43 44 45 51 52 53 54 55 "ashish mohan" wrote in message <jms2fr$sgd$1@newscl01ah.mathworks.com>... > i know this might sound like a dumb question but.. > i have a 5 by 1 matrix a=[1,2,3,4,...

Plotting diagonal half of matrix?
Hi, I need to plot a correlation matrix, I'm using imagesc(matrix) ...

Creating an array or matrix in matlab
Hey All !!! I need some advice on how to set a matrix using GUIDE. I want to create a [16 X 1] matrix. There are 16 check boxes. When the user clicks the first check box, data(1) should be created. When the user clicks the second check box, data(2) should be created and so on. This is what I have so far...... % --- Executes on button press in RUI1. handles.Permanent_Maxilla = []; function RUI1_Callback(hObject, eventdata, handles) if (get(hObject,'Value')== get(hObject,'Max')) %ie, if user clicks in the check box %assignin('base','Missing_Teeth', struct('Permanent_Maxilla',1)); data(1) = set(handles.Permanent_Maxilla,'Value',1); else %assignin('base','Missing_Teeth', struct('Permanent_Maxilla',0)); % Permanent_Maxilla2 = 0; data(1) = set(handles.Permanent_Maxilla,'Value',0); end % --- Executes on button press in LUI1. function LUI1_Callback(hObject, eventdata, handles) if (get(hObject,'Value')== get(hObject,'Max')) %ie, if user clicks in the check box data(16) = set(handles.Permanent_Maxilla,'Value',16); %handles.missing(16) = 16; else data(16) = set(handles.Permanent_Maxilla,'Value',0); %handles.missing(16) = 0; % Hint: get(hObject,'Value') returns toggle state of LUI1 end % --- Executes on button press in RUI2. function RUI2_Callback(hObject, eventdata, handles) if (get(hObject,'Value')== get(hObject,'M...

About the element of Matrix in Matlab #2
I have a difficulty in using Matlab to create a matrix. The matrix have its element is a random function of time-varying valuable t such as Gaussian or Sin. When t changes the matrix is changed and my system will use this matrix to calculate. My example: A is a square matrix 3,3. A(1,1) = 2 sin(t), A(1,2)=1 sin(t), A(1,3)= 3cos(t). A(2,1) = 1 cos(t),A(2,2) = 3sin(t), A(2,3) = 2cos(t). A (3,1)= 0.5sin(t),A(3,2) = 1.5sin(t),A(3,3)=3sin(t). A will be changed when t is running. So how I can matrix A to calculate. Please help me about Matlab code. Thanks. you can use a loop and a timer to keep updating the elements of matrix A ...

Block diagonal matrix construction
Suppose you have block A, B, C, ... How do you create a block diagonal matrix with blocks A, B, C, ... on the diagonal? Without looping through the elements of course. / Any ideas are much appreciated (google didn't help me) john wrote: > Suppose you have block A, B, C, ... How do you create a block diagonal > matrix with blocks A, B, C, ... on the diagonal? Without looping > through the elements of course. > > / Any ideas are much appreciated (google didn't help me) Does HELP BLKDIAG do what you want? -- Steve Lord slord@mathworks.com > > Suppose you have block A, B, C, ... How do you create a block diagonal > > matrix with blocks A, B, C, ... on the diagonal? > Does HELP BLKDIAG do what you want? No, not really. It is the dot dot dot that is the problem. I should have written block A_0, ..., A_n. My program doesn't know beforehand the value of n. There seems to be no obvious way to supply BLKDIAG with the input matrices in the same manner as diag: As soon as you can create a vector with the diagonal elements in a smart way, the problem is solved. Maybe I'll have to do a loop afterall. You might check out spdiags() If you tell us the form of your blocks, we may be able to suggest something better. Regards, Matt john wrote >> > Suppose you have block A, B, C, ... How do you create a block diagonal >> > matrix with blocks A, B, C, ... on the diagonal? > >> Does HEL...

Matching rows in one matrix to elements of another matrix
Hi, I'm having trouble with this part of my code. I'll try to simplify the problem to explain. I have the following matrices: A = [ 1 1 1; 1 1 1; 1 1 2; 1 1 2; 1 1 2; 1 2 1; 1 2 2]; B= [1; 2; 3; 4]; And I know the following Rules: If row = 1 1 1 then output = 1 If row = 1 1 2 then output = 2 And so on&#8230; So I&#8217;m looking to assign a number in B to a row in A. So my output would look like: C = [ 1; 1; 2; 2; 2; 3; 4] I&#8217;m having trouble since 1 1 1 is a row, I tried combing the row into a single number 111 but I&#8217;m having trouble making it work. I hope I was clear. Thanks for the help! "jrockv6e" wrote in message <iqtvln$9mp$1@newscl01ah.mathworks.com>... > Hi, I'm having trouble with this part of my code. I'll try to simplify the problem to explain. > > I have the following matrices: > A = [ 1 1 1; 1 1 1; 1 1 2; 1 1 2; 1 1 2; 1 2 1; 1 2 2]; > B= [1; 2; 3; 4]; > > And I know the following Rules: > If row = 1 1 1 then output = 1 > If row = 1 1 2 then output = 2 > And so on&#8230; > > So I&#8217;m looking to assign a number in B to a row in A. > So my output would look like: > C = [ 1; 1; 2; 2; 2; 3; 4] > > I&#8217;m having trouble since 1 1 1 is a row, I tried combing the row into a single number 111 but I&#8217;m having trouble making it work. I hope I was clear. > > Thanks for the help! A = [ 1 1 1; 1 1 1; 1 1 2; 1 ...

Comparing matrix to matrix
Hi all experienced matlab user, Here is my problem: I want to make it faster, so I don't want to use any for loop..(Since I want to compete with CPlex..I hope it is feasible :( ) Description: Input: A =[1 6 3; 2 4 6;4 5 3]; B = [1 3 5;2 7 4]; Output: [1 6 3; 4 5 3; 1 3 5] (Order is not important) **My goal is merging A and B and eliminate the non-dominated vector** i.e. A(2,:) and B(2,:) (The elements of [1 3 5] are all smaller than [2 4 6], so [2 4 6] is dominated by [1 3 5], similar to [2 7 4], which is dominated by [1 6 3]) Here is my current MATLAB Code: %I compare each element of A to the element of B to find A's dominated solution: A =[1 6 3; 2 4 6;4 5 3]; B = [1 3 5;2 7 4]; for iteration = 1: size(B,1) i = find(B(iteration,1) < A(:,1)); j = find(B(iteration,2) < A(i,2)); k = find(B(iteration,3) < A(i(j),3)); if isempty(k) ~=1 A(i(j(k)),:) = []; %delete the vector that is not dominated by others. end end %In reverse, I compare each element of B to the element of A to find B's dominated solution: for iteration = 1: size(A,1) i = find(A(iteration,1) < B(:,1)); j = find(A(iteration,2) < B(i,2)); k = find(A(iteration,3) < B(i(j),3)); if isempty(k) ~=1 B(i(j(k)),:) = []; %delete the vector that is not dominated by others. end end %End Does anyone know how to compare the matrix with different size by using find function?? Thanks! "Ho Cheung Brian" wrote in...

Forming a new matrix by taking particular elements of an existing matrix
Hello to all, I have a 6x5 matrix as below: 0 0 0 0 0 0 900 1000 1100 0 0 600 700 800 0 0 300 400 500 0 0 100 150 200 0 0 0 0 0 0 and I have to take its non-zero elements and form a 12x1 column matrix. Also i want tto take elements of the new matrix to start from the bottom left of the above matrix on. That is, 100 150 200 300 400 500 .... 1100 How can i do this? All help will be appreciated. Thanks in advance. Kenan On 12/23/2011 5:22 AM, Kenan wrote: > Hello to all, > > I have a 6x5 matrix as below: > > 0 0 0 0 0 > 0 900 1000 1100 0 > 0 600 700 800 0 > 0 300 400 500 0 > 0 100 150 200 0 > 0 0 0 0 0 > > and I have to take its non-zero elements and form a 12x1 column matrix. Also i want tto >take elements of the new matrix to start from the bottom left of the above matrix on. That is, > > 100 > 150 > 200 > 300 > 400 > 500 > ... > 1100 > > How can i do this? All help will be appreciated. Thanks in advance. > Kenan Not sure if I understood the rest of the question. but may be EDU>> sort(nonzeros(A)) ans = 100 150 200 300 400 500 600 7...

Select a particular element from each row of a matrix based on another matrix
I have a matrix A of size 6400 X 8 and another matrix B of size 6400 X 1( consisting of elements from 1-8). I want to extract one element from each row of matrix A according to the number(1-8) specified by matrix B. Thank you On 1/28/2012 3:06 PM, vishwanath wrote: > I have a matrix A of size 6400 X 8 and another matrix B of size 6400 X > 1( consisting of elements from 1-8). I want to extract one element from > each row of matrix A according to the number(1-8) specified by matrix B. > Thank you A(sub2ind(size(A),[1:length(B)]',B)) -- "dpb" wrote in message <jg1scn$p37$1@speranza.aioe.org>... > On 1/28/2012 3:06 PM, vishwanath wrote: > > I have a matrix A of size 6400 X 8 and another matrix B of size 6400 X > > 1( consisting of elements from 1-8). I want to extract one element from > > each row of matrix A according to the number(1-8) specified by matrix B. > > Thank you > > A(sub2ind(size(A),[1:length(B)]',B)) > > -- diag(A(:,B)) also works ...

Matlab: Creating a specific form of matrix
My question is.. what shoud I do if I have a, say, z = [1 2 3 4 5] and wants X to be repreat of z as below X=[ 1 2 3 4 5; 1 2 3 4 5; .... 1 2 3 4 5] (for n rows, where n will be entered later) I am new to matlab so I am not sure if there is a specific command for this. I appreciate your help. Thank you. "Kim K" <soon_5007@yahoo.om> wrote in message <hbftoi$98d$1@fred.mathworks.com>... > My question is.. > > what shoud I do if I have a, say, z = [1 2 3 4 5] > and wants X to be repreat of z as below > X=[ 1 2 3 4 5; 1 2 3 4 5; .... 1 2 3 4 5] (for n rows, where n will be entered later) > > I am new to matlab so I am not sure if there is a specific command for this. > I appreciate your help. Thank you. Write and save it as rp.m. The write in command z = [ 1 2 3 5]; rp(z, 50) And u get it. function a=rp (z, n) X = zeros(n, length(z)); for i=1:n X(i,:) = z; end a = X; On Oct 18, 10:28=A0pm, "Kim K" <soon_5...@yahoo.om> wrote: > My question is.. > > what shoud I do if I have a, say, z =3D [1 2 3 4 5] > and wants X to be repreat of z as below > X=3D[ 1 2 3 4 5; 1 2 3 4 5; .... 1 2 3 4 5] (for n rows, where n will be = entered later) > > I am new to matlab so I am not sure if there is a specific command for th= is. > I appreciate your help. Thank you. repmat(X,n,1); see help repmat for more info. best, arun. ...

Build a diagonal matrix from two vectors....????
Hi, as I am new to matlab so I need your help: Let say we have a matrix of two colums and many rows, like: A= a b c d e f g k Now what I want is to make a diagonal matrix from the rows of matrix A, like B=a b 0 0 0 0 0 0 o o c d 0 0 0 0 0 0 0 0 e f 0 0 0 0 0 0 0 0 g k Can any body help me! On 3/13/2012 11:44 AM, Florent Kadrija wrote: > Hi, > > as I am new to matlab so I need your help: > > Let say we have a matrix of two colums and many rows, like: > > A= a b > c d > e f > g k > > Now what I want is to make a diagonal matrix from the rows of matrix A, > like > > B=a b 0 0 0 0 0 0 o o c d 0 0 0 0 0 0 0 0 e f 0 0 0 0 0 0 0 0 g k > > Can any body help me! One way: [n,m] = size(A); temp = mat2cell(A,ones(1,n),m); B = blkdiag(temp{:}); -- Doug Schwarz dmschwarz&ieee,org Make obvious changes to get real email address. "Florent Kadrija" <florent.kadrija@gmail.com> wrote in message <jjnq0b$pge$1@newscl01ah.mathworks.com>... > Hi, > > as I am new to matlab so I need your help: > > Let say we have a matrix of two colums and many rows, like: > > A= a b > c d > e f > g k > > Now what I want is to make a diagonal matrix from the rows of matrix A, like > > B=a b 0 0 0 0 0 0 > o o c d 0 0 0 0 > 0 0 0 0 e f 0 0 > 0 0 0 0 0 0 g k B = spdiags(A,[0 1],4,4) B = full(B) % ...

Creating an array or matrix in matlab #2
Hey All !!! I need some advice on how to set a matrix using GUIDE. I want to create a [16 X 1] matrix. There are 16 check boxes. When the user clicks the first check box, data(1) should be created. When the user clicks the second check box, data(2) should be created and so on. This is what I have so far...... % --- Executes on button press in RUI1. handles.Permanent_Maxilla = []; function RUI1_Callback(hObject, eventdata, handles) if (get(hObject,'Value')== get(hObject,'Max')) %ie, if user clicks in the check box %assignin('base','Missing_Teeth', struct('Permanent_Maxilla',1)); data(1) = set(handles.Permanent_Maxilla,'Value',1); else %assignin('base','Missing_Teeth', struct('Permanent_Maxilla',0)); % Permanent_Maxilla2 = 0; data(1) = set(handles.Permanent_Maxilla,'Value',0); end % --- Executes on button press in LUI1. function LUI1_Callback(hObject, eventdata, handles) if (get(hObject,'Value')== get(hObject,'Max')) %ie, if user clicks in the check box data(16) = set(handles.Permanent_Maxilla,'Value',16); %handles.missing(16) = 16; else data(16) = set(handles.Permanent_Maxilla,'Value',0); %handles.missing(16) = 0; % Hint: get(hObject,'Value') returns toggle state of LUI1 end % --- Executes on button press in RUI2. function RUI2_Callback(hObject, eventdata, handles) if (get(hObject,'Value')== get(hObject,'M...

Plotting diagonal half of matrix? #2
Hi, I need to plot only the diagonal half (either upper or lower) of a matrix, how can I do that? So I have a correlation matrix (16x16), the upper diagonal is redundant, and I was wondering if there's a way to make it appear all white or something, and only plot the lower diagonal? I'm using something like imagesc(mymatrix); colorbar; to do this. Is there a way? Also, how can I make solid lines appear on the plot to delineate the squares? I tried 'Xgrid' 'On' option, it causes the grid lines to appear in the middle of the squares and not boundaries. If I shift the XTicks by 0.5 so that the ticks fall on edges and lines appear where I want, the labels also get shifted to the left :-( Thx! ...

Web resources about - Creating a J*J Diagonal Matrix with Jth Diagonal element is also a matrix - comp.soft-sys.matlab

Wikipedia:Creating a bot - Wikipedia, the free encyclopedia
It is often far simpler to request a bot job from an existing bot. If you have only periodic requests or are uncomfortable with programming languages, ...

U.K. Woman Faces 20 Months For Creating Fake Facebook Accounts, Sending Herself Abusive Messages
A woman in Cornwall in the U.K. came up with a creative way to use Facebook to accelerate a family spat, and it earned her 20 months in prison. ...

Sandi Krakowski’s Tips for Creating Great Content
Quick tips to help you create great content for your business.

Bug - Creating a Video.Watches Action stopped working - Facebook-Entwickler
Since today executing a POST on a me/video.wacthes endpoints no longer works, it was working around 10 hours ago since then the call always returns ...

Facebook simplifies process for creating repeat events
Facebook introduced a new feature for events this week that allows users to quickly create a similar event as one they previously hosted or attended. ...

The Obama campaign won by creating their own Facebook, with unique features for political campaigns.
... seen as too dangerous to nominate someone who is so thoroughly narcissistic, arrogant and dishonest. The Obama campaign won basically by creating ...

Creating A Great Startup Culture
... with any Bay Area startup these days (ping pong, beer on tap, catered lunches and Macbook Airs) – though these things are, of course, Creating ...

Campus Coaches: Creating a culture of wellness, one school at a time on the App Store
Read reviews, compare customer ratings, see screenshots, and learn more about Campus Coaches: Creating a culture of wellness, one school at a ...

Creating Economic Dynamism: Joseph E. Stiglitz
DAVOS/SWITZERLAND, 25JAN13 - Joseph E. Stiglitz, Professor, Columbia University, USA talks during the session 'Creating Economic Dynamism' at ...

PCB Tip, tip for creating pads on continuously coated PCB's - YouTube
Up date...SEE THIS UPDATED VIDEO... http://youtu.be/RKdsXU5iIF0 . I've been building some QRP transmitters and I see that some folk are cutting ...

Resources last updated: 3/31/2016 5:30:10 AM