Last change
on this file since 125 was
125,
checked in by gostiaux, 13 years ago
|
code simplification;
Can still be upgraded using function char (see last comment line)
|
File size:
1.1 KB
|
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:
|
---|
[89] | 9 | % Tabcell: (nx,ny) cell table, for nx lines separator: character used for separating displayed columns
|
---|
| 10 |
|
---|
[8] | 11 | function Tabchar=cell2tab(Tabcell,separator)
|
---|
| 12 | Tabchar={};%default
|
---|
[125] | 13 | [ni,nj]=size(Tabcell);
|
---|
| 14 |
|
---|
| 15 | %determine width of each column
|
---|
| 16 | widthcolumn=max(cellfun(@length,Tabcell));
|
---|
| 17 |
|
---|
[8] | 18 | %justify table
|
---|
[125] | 19 | for itab=1:ni
|
---|
[8] | 20 | charchain=[];
|
---|
[125] | 21 | for jtab=1:nj% read line
|
---|
[8] | 22 | textlu=Tabcell{itab,jtab};
|
---|
| 23 | if widthcolumn(jtab)>length(textlu)
|
---|
| 24 | blankstr=char(32*ones(1,widthcolumn(jtab)-length(textlu)));
|
---|
| 25 | textlu=[textlu blankstr];
|
---|
| 26 | end
|
---|
| 27 | if ~isempty(charchain)
|
---|
| 28 | textlu=[separator textlu];
|
---|
| 29 | end
|
---|
| 30 | charchain=[charchain textlu];
|
---|
| 31 | end
|
---|
| 32 | Tabchar(itab,1)={charchain};
|
---|
[125] | 33 | end
|
---|
| 34 |
|
---|
| 35 | %nb : char(Tabchar(:,jtab)) gives directly a column with the blanks filled |
---|
Note: See
TracBrowser
for help on using the repository browser.