f

#### block diagonal matrix

```Hi all,

Does anybody know what is the most efficient way to cobstruct a diagonal matrix from a vector of entries?
For example I want to create:
1     0     0
0     2     0
0     0     3
from:  a=1:3;
"blkdiag" does not work here since I need to enter the vector elements one by one which I can't since "a" can be very large.

Thanks,
Elnaz
```
 0
9/5/2013 8:16:06 PM
comp.soft-sys.matlab 211266 articles. 22 followers. lunamoonmoon (257) is leader.

1 Replies
415 Views

Similar Articles

[PageSpeed] 17

```On 9/5/2013 3:16 PM, Elnaz wrote:
> Hi all,
>
> Does anybody know what is the most efficient way to cobstruct a diagonal
?matrix from a vector of entries?
> For example I want to create:
> 1     0     0
> 0     2     0
> 0     0     3
> from:  a=1:3;
> "blkdiag" does not work here since I need to enter the vector elements one
>by one which I can't since "a" can be very large.
>
> Thanks,
> Elnaz
>

what is wrong with diag?

EDU>> a=1:3;
EDU>> diag(a)

1     0     0
0     2     0
0     0     3
```
 0
Nasser
9/5/2013 9:10:52 PM

Similar Artilces:

Block diagonal matrix from a skew-symmetric matrix
Dear Group members, I'm trying to solve the following algebra problem Consider a skew-symmetric matrix of the form: B=[0,A; -At,0] where 0 stands for a null matrix and At the transpose of matrix A. Is it possible to obtain a transformation of this matrix such as the new matrix in the new coordinates would be a block diagonal matrix of the form: C=[C1,0; 0,C2] with C=Tt * B * T, being T the transformation matrix? If possible how can I obtain such a transformation matrix? Thanks, RV ...

How do I create a diagonal matrix with block matricies on the diagonal?
Hello all, I need to create a square matrix that has square block matricies along the diagonal and zeros everywhere else. That is to say, I need to create a block diagonal matrix where each submatrix is different. The overall matrix needs to have the form: M = - - | sm1 0 0 | | 0 sm2 0 | | 0 0 sm3 | - - Any advice would be greatly appreciated. Either post a reply or email me directly(phatphreak74@yahoo.ca). thanks in advance, the phreak phat phreak wrote: > Hello all, > I need to create a square matrix that has square block matricies > along the diagonal and zeros everywhere el...

affecting a matrix rows as diagonal blocks in another matrix
Hi Suppose i have a matrix A= [1 4 5 8 7 3 6 5 2] I want to have a matrix B such each row of it has a row from A at the diagonal B=[1 4 5 0 0 0 0 0 0 0 0 0 8 7 3 0 0 0 0 0 0 0 0 0 6 5 2] how can i do it. I could do it with blkdiag but it supposes i input each row for the matrix, however i need something general since i need it for bigger matrices Thanks "matlab " <keep_smiling2100@yahoo.fr> wrote in message <jtkrgk\$js0\$1@newscl01ah.mathworks.com>... > Hi > Su...

Is a matrix block diagonal?
Hello, How would you find whether a given symmetric matrix is block diagonalizable (under shuffling of the indices)? My matrix is very large, binary and symmetric. It is not sparse, it has ~ 10% 1s. I want to find whether some indices cluster with others, or whether the whole thing is irreducible. Thanks, Pedro Pedro Bordalo wrote: > > > Hello, > > How would you find whether a given symmetric matrix is block > diagonalizable (under shuffling of the indices)? > > My matrix is very large, binary and symmetric. It is not sparse, > it > has ~ 10% 1s. I want to fi...

construct diagonal block matrix
I want to build a diagonal matrix such as 1 2 0 0 0 0 0 0 3 4 0 0 0 0 0 0 5 6 with a given (arbitrary) matrix, 1 2 3 4 5 6 without using loops and cell arrays (conversion takes time) blkdiag works with only parameters (a,b,c,d...) a,b,c,d... are row vectors. suggestions? Tim Hi Tim, I have a solution. Let M = [1 2; 3 4; 5 6]; Then, the matrix you are looking for can be computed with the following two lines: A = [diag(M(:,1)) diag(M(:,2))]; B = A(:,reshape(reshape(1:6,3,2)',1,6)) Hope this helps, Danny "Tim Yang" <dlISCool@gmail.com> wrote in message <h0u...

To construct a block diagonal matrix
I have two qubit density operator which have an n term approaching to infinity. I want to construct density matrix from it. which is a block dioganal matrix.I have some problem to do so.. Any help? On 4/3/2013 3:11 AM, Niaz khan wrote: > I have two qubit density operator which have an n term approaching to > infinity. I want to construct density matrix from it. which is a block > dioganal matrix.I have some problem to do so.. Any help? >> lookfor diagonal blkdiag - Block diagonal concatenation of matrix input arguments. diag - Diagonal matrices and diagonals of...

Block matrix: off Diagonal Matrices
Please Steve, you didn't tell how I can get the off diagonal matrices? The 2D laplacian matrix has off diagonal matrices of (alpha)I where I is identity matrix of the same dimension as the diagonal matrix. final matix: A = |B1 (a1)I ........ ... | |(a2) B2 (a2)I ........ | |....(a3)I B2 (a3)I ...| |.... ... ... | | (an)I Bn | Your help will be much appreciated! cheers E4Home wrote: > Please Steve, you didn't tell how I can get the off diagonal > matrices? The 2D laplacian matrix has off diagonal matrices of &g...

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 > &g...

HELP: Large Block Diagonal Matrix
I am solving an ill-defined linear equation A_Spatial_Comp * x2_1D_SimultReg = y_exp_1D_Spatial Under constraint: Where x2_1D_SimultReg > 0 &#8220;A_Spatial_Comp&#8221; is a block diagonal matrix with typical block diagonal size is 50 x 80. Here ONE block diagonal for each voxels. Each voxel adds 80 x 1 elements to x2_1D_SimultReg vector. If I try to solve the equation for 10000 voxels, then the elements of A_Spatial_Comp will be (5x10^5) x (8x10^5). I can divide this problem in smaller chunks so that time in solving these is minimized. I do need suggestion regarding ho...

Convert a matrix to block diagonal form
I want to convert A = [a, b, c, d e, f, g, h] to blk_A = [a, b, 0, 0 e, f, 0, 0 0, 0, c, d 0, 0, g, h] I tried blkdiag, but I want to do this without for loops. Additionally, does anyone know how to use mat2cell to use the A I defined to create cells that are of the form C{1} = [a, b e, f] C{2} = [c, d, g, h] Thanks, Asad > A = [a, b, c, d > e, f, g, h] > > to > > blk_A = [a, b, 0, 0 > e, f, 0, 0 > 0, 0, c, d >...

Inverse of square block diagonal matrix
I am trying to speed up the calculation of inverse of square block diagonal matrix. Currently I am taking inverse of the block one by one. Here is the code: function [ Ainv ] = blkinv( A, m ) C = cell(rows(A)/m,1); k = 1; for i = 1:m:rows(A) C{k} = inv(full(A(i:i+m-1,i:i+m-1))); k = k + 1; end Ainv = blkdiag(sparse(0,0),C{:}); end I wonder how I can compute the inverse in a parallel way. Any "multi-threaded function" can help? I just made anther attempt, function [ R ] = blkinv2( A, m ) B = mat2cell(full(reshape(nonzeros(A), m, [])), m, ones(rows(A)/m,1)*m)'; D = cellfun(@(X) sparse(inv(X)), B, 'UniformOutput', false); R = blkdiag(D{:}); end This is much faster, but still not parallel... "Lam" wrote in message <klqlgu\$n97\$1@newscl01ah.mathworks.com>... > I am trying to speed up the calculation of inverse of square block diagonal matrix. > > Currently I am taking inverse of the block one by one. Here is the code: > > function [ Ainv ] = blkinv( A, m ) > C = cell(rows(A)/m,1); > k = 1; > for i = 1:m:rows(A) > C{k} = inv(full(A(i:i+m-1,i:i+m-1))); > k = k + 1; > end > Ainv = blkdiag(sparse(0,0),C{:}); > end > > I wonder how I can compute the inverse in a parallel way. > Any "multi-threaded function" can help? http://www.mathworks.com/matlabcentral/fileexchange/25977-mtimesx-fast-matrix-multiply-with-multi-dimensiona...

Creating a sparse block diagonal matrix
Hi, does anyone know how to create what I think is called a sparse block diagonal matrix? Here is an example: I have one matrix that is sparse e.g. [1 0 0 0 ; 0 0 1 0 ; 0 0 1 0 ; 0 0 0 1 ] and want to create a new matrix where this matrix is repeted e.g. 10 times in the diagonal of a larger matrix i.e. a 40 x 40 matrix. How can I do this in a the most sparse and efficieant way? "Markus Nordberg" wrote in message <n7qmd3\$3bc\$1@newscl01ah.mathworks.com>... > Hi, > does anyone know how to create what I think is called a sparse block diagonal matrix? > ...

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! "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) w...

Create a block diagonal matrix from vectors
Hi, I'm a relatively new user in MATLAB and I'd appreciate if anyone can help me out with an answer or a reference on how to create block diagonal matrices from several vectors. As an example, if I have the following 4 vectors, d11=[1 5 9 13]; d12=[2 6 10 14]; d21=[3 7 11 15]; d22=[4 8 12 16]; what's the best way to create matrix D such that: D= 1 2 0 0 0 0 0 0 3 4 0 0 0 0 0 0 0 0 5 6 0 0 0 0 0 0 7 8 0 0 0 0 0 0 0 0 9 10 0 0 0 0 0 0 11 12 0 0 0 0...

Empty matrix and Diagonal matrix
Hi everyone I want to creat a large diagonal matrix.The main diagonal elements of the diagonal matrix is a 3x3 matrix. For example I have a matrix A(3x3),now I should obtain the diagnoal matrix B(300x300),can anybody tell me how to do it? Deeply appreciate your help! Thank you in advance! Nandy Erik wrote: > > > Hi everyone > I want to creat a large diagonal matrix.The main diagonal > elements > of the diagonal matrix is a 3x3 matrix. > For example I have a matrix A(3x3),now I should obtain the diagnoal > matrix B(300x300), >Others I want to know how to create an...

Construct Block Diagonal Matrix without for Loop
Hi everyone, I need to create a block diagonal matrix. This is the code I am using: %********** P = []; for i = 1:L % L changable parameter M = [2 a(i) b(i); ... a(i) 1 0; ... b(i) 0 1]; % a, b vectors size L P = blkdiag(P,M); end %********** Is there a way to create a block diagonal matrix with such structure without using a for loop (for the sake of performance)? Thanks in advance, Branko "Branko" wrote in message <io1nus\$lgp\$1@fred.mathworks.com>... > Hi everyone, > I need to create a block diagonal matrix. This is...

using a 3D matrix with a matlab script block
Hi all of you, &nbsp; it is possible to input a 3D matrix (e.g. 10x4x20) to a matlab script block or you have to unfold this data in a 2D array? &nbsp; Do you know what i have to do to input directly a 3D array (array of real numbers) to a matlab script block. &nbsp; P.D.; I'm using labview 7.0 and matlab 6.5 &nbsp; &nbsp; Thank you very much &nbsp; Larson Hi, as far as I know there is only the possibility to have an input for a 2D array to matlab scriptnode. Thus you should convert your 3D data to 2D in LV and reconvert it in your matlab code into 3D. When you...

Function for computing sparse matrix in block diagonal form
Hello, i am new in the world of Matlab and i would like to find a function that could compute a sparse matrix in a block diagonal form. I have tried some methods using Dulmage-Mendelsohn decompostion but it is trying to make a diagonal but not computing blocks... Fact is i am working with big non-square matrix : 715*48 and i wonder if that kind of input doesnt involve some problem with the dmperm function. In short, i am looking for something that could permute rows and columns in order to get a blok diagonal form. A=( X X X N=( N1 0 0 X X X ----> 0 N2 0 X X X) 0 0 N3) Thanks for...

3-D Matrix elements to 2-D Block Diagonal
I have a [N,P,K] 3D matrix. I want to construct a 2-D [N*K,P*K] Block Diagonal matrix from it. i.e. I have A(:,:,1) = A1 A(:,:,2) = A2 . . A(:,:,K) = AK where Ai = [N by P] And I want: |A1 | | A2 | B = | . | | . | | AK| How can I do such a thing? I thank you in advance. A=rand(2,2,4) c=num2cell(A,[1 2]) M=blkdiag(c{:}) Bruno "Bruno Luong" <b.luong@fogale.findmycountry> wrote in...

Help with an IMMENSE block diagonal matrix: results that are needed asap depend on this
Hey everyone, So here's the situation. I have a 41 by 41 by 11 array of voxels, and associated with each voxel is a matrix X that that is 1022 by 48. I need to create the block diagonal matrix X_(1,1,1) 0 . . . 0 0 X_(2,1,1) . . . 0 .. . . .. . . 0 0 . . . X_(41, 41, 11) where X_(v1,v2,v3) is the X matrix associated with voxel (v1,v2,v3). I need help in filling this matrix out in a reasonable amount of time. Right now what I have d...

Fast Matrix*Diagonal*Matrix operation
Hi there, I have a code that computes Q'*D(t)*Q many times. Here Q is a fixed mxn matrix with m < n, while the diagonal matrix D depends on the iteration t. Because I have so many iterations that the operation slows done the entire process. I am wondering if there is any way to obtain Q'*D(t)*Q as fast as possible. Maybe from the result of Q'*Q or some kind of decomposition of Q'*Q? Thanks in advance! best, Gongguo "Gongguo Tang" wrote in message <ii7d79\$lto\$1@fred.mathworks.com>... > Hi there, > > I have a code that compute...

how to write a matlab function block in simulation block
i want to write a matlab function block in simulation block naidu wrote: > > > i want to write a matlab function block in simulation block have a look on this URL: <http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/ug/f6-6010.html> ...

connecting mux block with matlab function block
Hi, I connected mux with matlab function block with three inputs to mux and one output to function block. After running the error is that the matlab function block is unable to receive or treat input signal from mux block as it is unable to access 3 components of a vector which I am feeding to function block. Can anyone suggest me better way of connecting mux with function block. ...

procs/blocks
Well, maybe not blocks with blocks but blocks with yield? although right now, I only have a fix for procs with blocks and not blocks with blocks via blocks with yield when a proc block is not in stock... class Proc alias __proc_block_call call alias __proc_block_indexer [] def call(*args, &block) __proc_block_call(*(block.nil? ? args : args << block)) end def [](*args, &block) __proc_block_indexer(*(block.nil? ? args : args << block)) end end ----- usage prc = Proc.new {|arg, proc_block| p arg proc_block[arg] } prc.call("Foo") {|...

Web resources about - block diagonal matrix - comp.soft-sys.matlab

Diagonal - Wikipedia, the free encyclopedia
A diagonal is a line joining two nonconsecutive vertices of a polygon or polyhedron . Informally, any sloping line is called diagonal. The word ...

Number Join + : Join every single number. Horizontal, vertical and diagonal on the App Store on iTunes ...
Get Number Join + : Join every single number. Horizontal, vertical and diagonal on the App Store. See screenshots and ratings, and read customer ...

Police investigate four deliberately lit fires at Rider St, Sandery Ave and Diagonal Rd, Seacombe Gardens ...
POLICE need information to find who deliberately lit four small rubbish or grass fires at Seacombe Gardens early on Tuesday.

WSJ again claims Apple working on larger-screened iPhones up to 6" diagonal [u]
Apple is reportedly testing a variety of next-generation iPhones with larger screen sizes, some up to six inches diagonally, though the devices ...

SteamVR instructions show wireless controllers, 15’ diagonal playspace
New headset has less weight, fewer wires, and Wii-like wrist straps on the controls.

2015 BMW X4 slides in on the diagonal starting at \$45,625 in the US
Filed under: New York Auto Show , Crossover , BMW , Luxury If BMW has shown us anything, it's a knack for creating niches and expanding its ...

UAB Blazers Make Tremendous Diagonal Pass to Set Up Big-Time 3-Pointer - Bleacher Report
... aren't giving up yet as they battle it out with the UCLA Bruins in their third-round matchup. Chris Cokley sets up Denzell Watts with the diagonal ...

Witness: Plane did "diagonal cartwheel"
Eyewitness Anthony Castrani describes how Asiana flight 214 performed a "side motion diagonal cartwheel" as it crashed while landing at San Francisco ...

Business owners reeling after burst pipe shuts down Diagonal Plaza
Boulder's Diagonal Plaza shopping center will be shut down for the foreseeable future due to extensive water damage caused by a broken pipe, ...

City Rejects Plea to Keep Diagonal Runways to Reduce O'Hare Noise
... are used at night to reduce the noise over some neighborhoods. O'HARE — O'Hare Airport officials Friday rejected pleas to keep two diagonal ...

Resources last updated: 3/8/2016 5:37:43 AM