From octave-sources-request at bevo dot che dot wisc dot edu Mon Jun 26 08:54:26 2000 Subject: blkdiag.m (Re:matlab compatibility) From: Daniel Calvelo To: octave-sources at bevo dot che dot wisc dot edu Date: Mon, 26 Jun 2000 15:02:28 +0200 (CET) In http://www.che.wisc.edu/octave/mailing-lists/octave-sources/2000/93, pkienzle at kienzle dot powernet dot co dot uk remarks: [snip] . . Matrix manipulation. reshape - Change size. diag - Diagonal matrices and diagonals of matrix. x blkdiag - Block diagonal concatenation. [snip] There you are :) ----------------------------------blkdiag.m---------------------------- function y = blkdiag(...), ## Build a block-diagonal matrix from all the arguments ## Daniel Calvelo 2000. Use, modify and debug at will nin = 0; va_start(); sizes = zeros( nargin, 2 ); while( ++nin <= nargin ), m = va_arg(); if ~isnumeric( m ), error("Non-numeric argument found."); endif sizes(nin,:) = size( m ); endwhile csz = [[0 0];cumsum(sizes)] y = zeros( max(csz) ); va_start(); nin = 0; while(++nin <= nargin), y(csz(nin,1)+1:csz(nin+1,1) , csz(nin,2)+1:csz(nin+1,2)) = va_arg(); endwhile endfunction ------------------------------------------------------------------------ -- Daniel Calvelo Aros calvelo at lifl dot fr ----------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.che.wisc.edu/octave/octave.html How to fund new projects: http://www.che.wisc.edu/octave/funding.html Subscription information: http://www.che.wisc.edu/octave/archive.html -----------------------------------------------------------------------