MatrixBerryCore
cell2tablestr.m
Go to the documentation of this file.
1 function tableStr=cell2tablestr(titleList,dataCell,colSepSeq,varargin)
2 import mxberry.core.throwerror;
3 import mxberry.core.parseparext;
4 [~,~,isMatlabSyntax,isUniformOutput,minSepCount,numPrecision]=...
5  parseparext(varargin,...
6  {'isMatlabSyntax','uniformOutput','minSepCount','numPrecision';...
7  false,true,1,3;...
8  @(x)islogical(x)&&isscalar(x),@(x)islogical(x)&&isscalar(x),...
9  @(x)isscalar(x)&&isnumeric(x)&&(x>0)&&(fix(x)==x),...
10  @(x)isscalar(x)&&isnumeric(x)&&(x>0)&&(fix(x)==x)},0);
11 %
12 [nRows,nCols] = size(dataCell);
13 %
14 nRowsRes=nRows;
15 if ~isempty(titleList)
16  nRowsRes=nRowsRes+1;
17  dataCell=[titleList;dataCell];
18 end
19 %
20 %% process data cell
21 dataCell=cellfun(@cellformatter,dataCell,'UniformOutput',false);
22 %
23 %% insert separators
24 resCell=cell(nRowsRes,1);
25 for iCol=1:(nCols-1)
26  dataColCell=dataCell(:,iCol);
27  lenColCell=cellfun(@length,dataColCell,'UniformOutput',false);
28  lenColVec=cell2mat(lenColCell);
29  maxLength=max(lenColVec(:))+minSepCount;
30  sepCell=cellfun(@(x)(repmat(colSepSeq,1,maxLength-x)),lenColCell,...
31  'UniformOutput',false);
32  resCell=strcat(resCell,strcat(dataCell(:,iCol),sepCell));
33 end
34 if nRowsRes==0
35  nRowsRes=1;
36 end
37 if nCols>0
38  resCell=strcat(resCell,dataCell(:,end));
39 else
40  resCell=repmat({''},[nRowsRes,1]);
41 end
42 %
43 if isMatlabSyntax
44  resCell=cellfun(@horzcat,repmat({'{'},[nRowsRes,1]),resCell,...
45  'UniformOutput',false);
46  resCell=cellfun(@horzcat,resCell,repmat({'}'},[nRowsRes,1]),...
47  'UniformOutput',false);
48 end
49 %
50 %% convert to char array if necessary
51 %
52 if isUniformOutput
53  tableStr=char(resCell);
54 else
55  tableStr=resCell;
56 end
57  function outCont=cellformatter(inpCont)
58  switch class(inpCont)
59  case {'double','single'}
60  outCont=num2str(inpCont,numPrecision);
61  case 'logical'
62  outCont=num2str(inpCont);
63  case 'struct'
64  outCont='<structure>';
65  otherwise
66  if isnumeric(inpCont)
67  outCont=num2str(inpCont);
68  else
69  outCont=inpCont;
70  end
71  end
72  end
73 end
function parseparext(in args, in propNameValMat, in varargin)
PARSEPAREXT behaves in the same way as mxberry.core.parseparams but returns property values in a more...
function repmat(in inpArray, in varargin)
function cell2tablestr(in titleList, in dataCell, in colSepSeq, in varargin)
CELL2TABLESTR - converts a cell array into a table-like char array (or a cell array of strings repres...
function cellformatter(in inpCont)
function cell2mat(in inpCArr)
CELL2MAT does the same as the built-in cell2mat function but a) 20% faster b) works with cell arrays ...