source: trunk/src/cell2tab.m @ 126

Last change on this file since 126 was 126, checked in by gostiaux, 14 years ago

help updated

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: (ni,nj) cell table, for ni lines
10% separator: character used for separating displayed columns
11
12function Tabchar=cell2tab(Tabcell,separator)
13Tabchar={};%default
14[ni,nj]=size(Tabcell);
15
16%determine width of each column
17widthcolumn=max(cellfun(@length,Tabcell));
18
19%justify table
20for 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};
34end
35
36%nb : char(Tabchar(:,jtab)) gives directly a column with the blanks filled
Note: See TracBrowser for help on using the repository browser.