source: trunk/src/cell2tab.m @ 127

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

help updated

File size: 1.1 KB
RevLine 
[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]12function Tabchar=cell2tab(Tabcell,separator)
13Tabchar={};%default
[125]14[ni,nj]=size(Tabcell);
15
16%determine width of each column
17widthcolumn=max(cellfun(@length,Tabcell));
18
[8]19%justify table
[125]20for 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]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.