Home > classes > @ssm > cell_recut.m

cell_recut

PURPOSE ^

cuts a matrix into blocks stored inside cell array

SYNOPSIS ^

function a_out = cell_recut(a, rowsizes, colsizes)

DESCRIPTION ^

 cuts a matrix into blocks stored inside cell array
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: cell_recut  cuts a matrix into blocks stored inside cell
 array. Blocks with zeros are nullified, except in the diagonal (to
 preserve information on matrix size)
 
 CALL: [cell3] = ssm.cell_recut(mat1,rowsizes,colsizes)

 INPUTS: 
       mat1     - numeric array to be cut in pieces
       rowsizes - vector giving block height 
       colsizes - vector giving block width 

 OUTPUTS: 
       cell3 - cell array of matrices representing a matrix by blocs.
               blocs may be empty
 
 ***** There are no parameters *****

 VERSION: '$Id: $'


 HISTORY:
 07-08-2008

 TO DO : 
 check ME in case of mixed symbolic and double 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 to deal with matrices whose size is not defined

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % cuts a matrix into blocks stored inside cell array
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: cell_recut  cuts a matrix into blocks stored inside cell
0005 % array. Blocks with zeros are nullified, except in the diagonal (to
0006 % preserve information on matrix size)
0007 %
0008 % CALL: [cell3] = ssm.cell_recut(mat1,rowsizes,colsizes)
0009 %
0010 % INPUTS:
0011 %       mat1     - numeric array to be cut in pieces
0012 %       rowsizes - vector giving block height
0013 %       colsizes - vector giving block width
0014 %
0015 % OUTPUTS:
0016 %       cell3 - cell array of matrices representing a matrix by blocs.
0017 %               blocs may be empty
0018 %
0019 % ***** There are no parameters *****
0020 %
0021 % VERSION: '$Id: $'
0022 %
0023 %
0024 % HISTORY:
0025 % 07-08-2008
0026 %
0027 % TO DO :
0028 % check ME in case of mixed symbolic and double
0029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0030 function a_out = cell_recut(a, rowsizes, colsizes)
0031 % to deal with matrices whose size is not defined
0032 rowsizes = max(zeros(size(rowsizes)), rowsizes);
0033 colsizes = max(zeros(size(colsizes)), colsizes);
0034 rowrank = cumsum([1 rowsizes]);
0035 colrank = cumsum([1 colsizes]);
0036 Nrow = length(rowsizes);
0037 Ncol = length(colsizes);
0038 a_out = cell(Nrow, Ncol);
0039 for i=1:Nrow
0040   for j=1:Ncol
0041     rowmin = rowrank(i);
0042     rowmax = rowrank(i+1)-1;
0043     colmin = colrank(j);
0044     colmax = colrank(j+1)-1;
0045     
0046     if rowmax >= rowmin && colmax >=colmin
0047       if isa(a, 'sym')
0048         try
0049           a_out{i,j} = double(a(rowmin:rowmax, colmin:colmax));
0050           if ~(i==j) && norm(a_out{i,j})==0 
0051             a_out{i,j}=[];
0052           end
0053         catch
0054           a_out{i,j} = a(rowmin:rowmax, colmin:colmax);
0055         end
0056       elseif ~norm(a(rowmin:rowmax, colmin:colmax))==0
0057           a_out{i,j} = double(a(rowmin:rowmax, colmin:colmax));
0058       elseif i==j
0059         a_out{i,j} = zeros(rowsizes(i), colsizes(j));
0060       end
0061     elseif i==j
0062       a_out{i,j} = zeros(rowsizes(i), colsizes(j));
0063     end
0064   end
0065 end
0066 end

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003