1 | %'cell2tab': transform a Matlab cell in a character array suitable for display in a table
|
---|
2 | %------------------------------------------------------------------------
|
---|
3 | % function Tabchar=cell2tab(Tabcell,separator)
|
---|
4 | %
|
---|
5 | % OUTPUT:
|
---|
6 | % Tabchar: column cell of char strings suitable for display (equal length)
|
---|
7 | %
|
---|
8 | % INPUT:
|
---|
9 | % Tabcell: (ni,nj) cell matrix of char strings to be displayed as ni lines , nj column
|
---|
10 | % separator: char string used for separating displayed columns
|
---|
11 |
|
---|
12 | %=======================================================================
|
---|
13 | % Copyright 2008-2019, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
14 | % http://www.legi.grenoble-inp.fr
|
---|
15 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
16 | %
|
---|
17 | % This file is part of the toolbox UVMAT.
|
---|
18 | %
|
---|
19 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
20 | % it under the terms of the GNU General Public License as published
|
---|
21 | % by the Free Software Foundation; either version 2 of the license,
|
---|
22 | % or (at your option) any later version.
|
---|
23 | %
|
---|
24 | % UVMAT is distributed in the hope that it will be useful,
|
---|
25 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
26 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
27 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
28 | %=======================================================================
|
---|
29 |
|
---|
30 | function Tabchar=cell2tab(Tabcell,separator)
|
---|
31 | [ni,nj]=size(Tabcell);
|
---|
32 |
|
---|
33 | %determine width of each column
|
---|
34 | if isequal(ni,1)
|
---|
35 | widthcolumn=cellfun('length',Tabcell);% case of a single line, no justification used
|
---|
36 | else
|
---|
37 | widthcolumn=max(cellfun('length',Tabcell));
|
---|
38 | end
|
---|
39 | lsep=numel(separator); %nbre of characters of the separator
|
---|
40 | nbchar_line=(sum(widthcolumn)+(nj-1)*lsep); %total nbre of characters in each output line
|
---|
41 | default_line=blanks(nbchar_line); %default blank line
|
---|
42 | Tabmat=reshape(blanks(nbchar_line*ni),ni,nbchar_line);
|
---|
43 | Tabchar=mat2cell(Tabmat,ones(1,ni),nbchar_line); %default output
|
---|
44 |
|
---|
45 | %justify table
|
---|
46 | for itab=1:ni
|
---|
47 | charchain=default_line;
|
---|
48 | for jtab=1:nj% read line
|
---|
49 | textlu=Tabcell{itab,jtab};
|
---|
50 | if jtab==1
|
---|
51 | charchain(1:length(textlu))=textlu;%introduce separator chain string except for the first column
|
---|
52 | ind_column=widthcolumn(1);%new current char index in the line
|
---|
53 | else
|
---|
54 | charchain(ind_column+1:ind_column+lsep)=separator;%introduce separator chain string except for the first column
|
---|
55 | charchain(ind_column+lsep+1:ind_column+lsep+length(textlu))=textlu;%introduce separator chain string except for the first column
|
---|
56 | ind_column=ind_column+widthcolumn(jtab)+lsep;
|
---|
57 | end
|
---|
58 | end
|
---|
59 | Tabchar(itab,1)={charchain};
|
---|
60 | end
|
---|