Constructing a block diagonal matrix using the contents of a cell

2 次查看(过去 30 天)
Hi, I have created a structure which contains, say, four vectors of different lengths. So, for example:
AA=[98x1 double] [20x1 double] [98x1 double] [20x1 double]
I then use these vectors to pick out certain elements of a non-full matrix A, so, for instance (A(AA{1},AA{1}).
I was looking for a quick way to create a block diagonal matrix, with the entries, (A(AA{1},AA{1}) in the entry (1,1), (A(AA{2},AA{2})in the entry (2,2), (A(AA{3},AA{3}) in the entry (3,3) and (A(AA{4},AA{4}) in the entry (4,4) (ie: on the diagonals), with zeros obviously in the other positions. Is anyone aware of the best way to achieve this? I am unsure how to `tell' Matlab the dimension of the zero's in the block matrix, which will differ on an entry-by-entry basis.
Any help would be much appreciated.

回答(1 个)

Laura Proctor
Laura Proctor 2011-12-13
I'm not quite sure of your end goal, the syntax "A(AA{1},AA{1}) in the entry (1,1)" isn't clear to me.
But, you may find the function blkdiag useful.

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by