Leigh J. Halliwell wrote:
> Dear J Forum:
> I have two matrices M1 and M2.  How do I create a matrix that is
> block-diagonal in them (zero elsewhere)?  Thanks.


I use the following, due to Jose Mario Quintana: see

http://www.jsoftware.com/pipermail/general/2000-August/004086.html

BlockDiag=. >@:((([ ,. ({.@:$@:[ , {:@:$@:]) $ 0"_) , (({.@:$@:] ,
{:@:$@:[)$ 0"_) ,. ])&.>"0 0/)

   ]a=:i. 2 2
0 1
2 3
   ]b=:i. 3 3
0 1 2
3 4 5
6 7 8
   BlockDiag a;b
0 1 0 0 0
2 3 0 0 0
0 0 0 1 2
0 0 3 4 5
0 0 6 7 8

Best wishes,

John



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to