| Line | |
|---|
| 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: character array suitable for table display
|
|---|
| 7 | %
|
|---|
| 8 | % INPUT:
|
|---|
| 9 | % Tabcell: (ni,nj) cell table, for ni lines
|
|---|
| 10 | % separator: character used for separating displayed columns
|
|---|
| 11 |
|
|---|
| 12 | function Tabchar=cell2tab(Tabcell,separator)
|
|---|
| 13 | Tabchar={};%default
|
|---|
| 14 | [ni,nj]=size(Tabcell);
|
|---|
| 15 |
|
|---|
| 16 | %determine width of each column
|
|---|
| 17 | widthcolumn=max(cellfun(@length,Tabcell));
|
|---|
| 18 |
|
|---|
| 19 | %justify table
|
|---|
| 20 | for itab=1:ni
|
|---|
| 21 | charchain=[];
|
|---|
| 22 | for jtab=1:nj% read line
|
|---|
| 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};
|
|---|
| 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.