Home > classes > @ssm > cell_select.m

cell_select

PURPOSE ^

CELL_SELECT selects lines and columns of a block defined matrix stored in

SYNOPSIS ^

function [cell_mat_out, rowsizes_out, colsizes_out] = cell_select(varargin)

DESCRIPTION ^

 CELL_SELECT selects lines and columns of a block defined matrix stored in
 a cell array 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: cell_select selects lines and columns of a blck defined
 matrix stored in a cell array

 CALL: [cell2] = ssm.cell_recut(cell1,rowsizes,colsizes)

 INPUTS:
       cell1    - block defined matrix in cell array
       rowsizes - vector giving block height
       colsizes - vector giving block width

 OUTPUTS:
       cell2 - cell array of matrices representing a matrix by blocs.
               blocs may be empty

 ***** There are no parameters *****

 VERSION: '$Id: $'


 HISTORY:
 12-08-2008

 TO DO :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % CELL_SELECT selects lines and columns of a block defined matrix stored in
0002 % a cell array
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 % DESCRIPTION: cell_select selects lines and columns of a blck defined
0006 % matrix stored in a cell array
0007 %
0008 % CALL: [cell2] = ssm.cell_recut(cell1,rowsizes,colsizes)
0009 %
0010 % INPUTS:
0011 %       cell1    - block defined matrix in cell array
0012 %       rowsizes - vector giving block height
0013 %       colsizes - vector giving block width
0014 %
0015 % OUTPUTS:
0016 %       cell2 - 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 % 12-08-2008
0026 %
0027 % TO DO :
0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0029 function [cell_mat_out, rowsizes_out, colsizes_out]  = cell_select(varargin)
0030 
0031   cell_mat_in = varargin{1};
0032   rowsizes = varargin{2};
0033   colsizes = varargin{3};
0034   rowselect  = varargin{4};
0035   colselect = varargin{5};
0036 
0037   %% field for rows
0038   Nrows    = size(cell_mat_in, 1);
0039   rows_log = cell(1,Nrows);
0040   if strcmp(rowselect, 'ALL')
0041     for i=1:Nrows
0042       rows_log{i} = true(1,rowsizes(i));
0043     end
0044   elseif iscellstr(rowselect)
0045     rownames = varargin{6};
0046     for i=1:Nrows
0047       rows_log{i} = true(1, rowsizes(i));
0048       for j=1:rowsizes(i)
0049         rows_log{i}(j) = (sum(ismember(rowselect, rownames{i}{j} ))>0);
0050       end
0051     end
0052   elseif isa(rowselect, 'cell')
0053     for i=1:Nrows
0054       if isa(rowselect{i},'double')
0055         rows_log{i} = rowselect{i};
0056       elseif isa(rowselect{i},'logical')
0057         rows_log{i} = rowselect{i};
0058         if ~length(rowselect{i})==rowsizes(i)
0059           error(['parameter ''rowselect'' is of wrong size for block numer ', num2str(i)]);
0060         end
0061       else
0062         error('parameter ''rowselect'' is of wrong type')
0063       end
0064     end
0065   else
0066     error('parameter ''rowselect'' is of wrong type')
0067   end
0068 
0069   %% field for cols
0070   Ncols    = size(cell_mat_in, 2);
0071   cols_log = cell(1,Ncols);
0072   if strcmp(colselect, 'ALL')
0073     for i=1:Ncols
0074       cols_log{i} = true(1,colsizes(i));
0075     end
0076   elseif iscellstr(colselect)
0077     colnames = varargin{7};
0078     for i=1:Ncols
0079       cols_log{i} = true(1, colsizes(i));
0080       for j=1:colsizes(i)
0081         cols_log{i}(j) = (sum(ismember(colselect, colnames{i}{j} ))>0);
0082       end
0083     end
0084   elseif isa(colselect, 'cell')
0085     for i=1:Ncols
0086       if isa(colselect{i},'double')
0087         cols_log{i} = colselect{i};
0088       elseif isa(colselect{i},'logical')
0089         cols_log{i} = colselect{i};
0090         if ~length(colselect{i})==colsizes(i)
0091           error(['parameter ''colselect'' is of wrong size for block numer ', num2str(i)]);
0092         end
0093       else
0094         error('parameter ''colselect'' is of wrong type')
0095       end
0096     end
0097   else
0098     error('parameter ''colselect'' is of wrong type')
0099   end
0100 
0101   %% assigning content
0102   cell_mat_out = cell(Nrows, Ncols);
0103   for i=1:Nrows
0104     for j=1:Ncols
0105       if ~isequal(cell_mat_in{i,j}, [])
0106         if ~isempty(rows_log{i}) && ~isempty(cols_log{j}) 
0107           cell_mat_out{i,j} = cell_mat_in{i,j}(rows_log{i},cols_log{j});
0108         else
0109           switch class(cell_mat_in{i,j})
0110             case {'double' 'sym'}
0111               cell_mat_out{i,j} = zeros( sum(rows_log{i}>0), sum(cols_log{j}>0));
0112             case 'cell'
0113               cell_mat_out{i,j} = cell( sum(rows_log{i}>0), sum(cols_log{j}>0));
0114           end
0115         end
0116       end
0117     end
0118   end
0119 
0120   rowsizes_out = zeros(1, Nrows);
0121   for i=1:Nrows
0122     if isa(rows_log{i},'double')
0123       rowsizes_out(i) = length(rows_log{i});
0124     else
0125       rowsizes_out(i) = sum(rows_log{i});
0126     end
0127   end
0128 
0129   colsizes_out = zeros(1, Ncols);
0130   for i=1:Ncols
0131     if isa(cols_log{i},'double')
0132       colsizes_out(i) = length(cols_log{i});
0133     else
0134       colsizes_out(i) = sum(cols_log{i});
0135     end
0136   end
0137 end

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