Rev | Line | |
---|
[8] | 1 | %'cell2tab': transform a Matlab cell in a character array suitable for display in a table
|
---|
[89] | 2 | %------------------------------------------------------------------------
|
---|
| 3 | % function Tabchar=cell2tab(Tabcell,separator)
|
---|
| 4 | %
|
---|
| 5 | % OUTPUT:
|
---|
| 6 | % Tabchar: character array suitable for table display
|
---|
| 7 | %
|
---|
[8] | 8 | % INPUT:
|
---|
[126] | 9 | % Tabcell: (ni,nj) cell table, for ni lines
|
---|
| 10 | % separator: character used for separating displayed columns
|
---|
[89] | 11 |
|
---|
[8] | 12 | function Tabchar=cell2tab(Tabcell,separator)
|
---|
| 13 | Tabchar={};%default
|
---|
[125] | 14 | [ni,nj]=size(Tabcell);
|
---|
| 15 |
|
---|
| 16 | %determine width of each column
|
---|
| 17 | widthcolumn=max(cellfun(@length,Tabcell));
|
---|
| 18 |
|
---|
[8] | 19 | %justify table
|
---|
[125] | 20 | for itab=1:ni
|
---|
[8] | 21 | charchain=[];
|
---|
[125] | 22 | for jtab=1:nj% read line
|
---|
[8] | 23 | textlu=Tabcell{itab,jtab};
|
---|
| 24 | if widthcolumn(jtab)>length(textlu)
|
---|
| 25 | blankstr=char(32*ones(1,widthcolumn(jtab)-length(textlu)));
|
---|
| 26 | textlu=[textlu blankstr];
|
---|
| 27 | end
|
---|
| 28 | if ~isempty(charchain)
|
---|
| 29 | textlu=[separator textlu];
|
---|
| 30 | end
|
---|
| 31 | charchain=[charchain textlu];
|
---|
| 32 | end
|
---|
| 33 | Tabchar(itab,1)={charchain};
|
---|
[125] | 34 | end
|
---|
| 35 |
|
---|
| 36 | %nb : char(Tabchar(:,jtab)) gives directly a column with the blanks filled |
---|
Note: See
TracBrowser
for help on using the repository browser.