Home > classes > @ssm > cell_select.m

cell_select

PURPOSE ^

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

SYNOPSIS ^

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

DESCRIPTION ^

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

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003