|
Last change
on this file since 125 was
125,
checked in by gostiaux, 15 years ago
|
|
code simplification;
Can still be upgraded using function char (see last comment line)
|
|
File size:
1.1 KB
|
| 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: (nx,ny) cell table, for nx lines separator: character used for separating displayed columns
|
|---|
| 10 |
|
|---|
| 11 | function Tabchar=cell2tab(Tabcell,separator)
|
|---|
| 12 | Tabchar={};%default
|
|---|
| 13 | [ni,nj]=size(Tabcell);
|
|---|
| 14 |
|
|---|
| 15 | %determine width of each column
|
|---|
| 16 | widthcolumn=max(cellfun(@length,Tabcell));
|
|---|
| 17 |
|
|---|
| 18 | %justify table
|
|---|
| 19 | for itab=1:ni
|
|---|
| 20 | charchain=[];
|
|---|
| 21 | for jtab=1:nj% read line
|
|---|
| 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};
|
|---|
| 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.