Changeset 128 for trunk/src/cell2tab.m


Ignore:
Timestamp:
Nov 21, 2010, 10:06:11 PM (14 years ago)
Author:
sommeria
Message:

series: give writting access to the group for all subdirectories produced
uvmat.fig: change of vect and scalar frames (to be consistent with view_field)
uvmat: various cleaning
plot_field: various cleaning to improve axes definition and avoid blinking
geometry_calib: improved dispay of point coordiantes, improved link with dataview for REPLICATE.
struct2nc: repair bug , file was not closed.
cell2tab: cleaning
dataview: improve the browser
civ: solve pb of image naming

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cell2tab.m

    r126 r128  
    44%
    55% OUTPUT:
    6 % Tabchar: character array suitable for table display
     6% Tabchar: column cell of char strings suitable for display (equal length)
    77%
    88% INPUT:
    9 % Tabcell: (ni,nj) cell table, for ni lines
    10 % separator: character used for separating displayed columns
     9% Tabcell: (ni,nj) cell matrix of char strings to be displayed as  ni lines , nj column
     10% separator: char string used for separating displayed columns
    1111
    1212function Tabchar=cell2tab(Tabcell,separator)
    13 Tabchar={};%default
    1413[ni,nj]=size(Tabcell);
    1514
    1615%determine width of each column
    17 widthcolumn=max(cellfun(@length,Tabcell));
     16if isequal(ni,1)
     17    widthcolumn=cellfun('length',Tabcell);% case of a single line, no justification used
     18else
     19    widthcolumn=max(cellfun('length',Tabcell));
     20end
     21lsep=numel(separator); %nbre of characters of the separator
     22nbchar_line=(sum(widthcolumn)+(nj-1)*lsep); %total nbre of characters in each output line
     23default_line=blanks(nbchar_line); %default blank line
     24Tabmat=reshape(blanks(nbchar_line*ni),ni,nbchar_line);
     25Tabchar=mat2cell(Tabmat,ones(1,ni),nbchar_line); %default output
    1826
    1927%justify table
    2028for itab=1:ni   
    21     charchain=[];        
     29    charchain=default_line; 
    2230    for jtab=1:nj% read line
    2331        textlu=Tabcell{itab,jtab};
    24         if widthcolumn(jtab)>length(textlu)
    25             blankstr=char(32*ones(1,widthcolumn(jtab)-length(textlu)));
    26             textlu=[textlu blankstr];
     32        if jtab==1
     33            charchain(1:length(textlu))=textlu;%introduce separator chain string except for the first column
     34            ind_column=widthcolumn(1);%new current char index in the line
     35        else
     36            charchain(ind_column+1:ind_column+lsep)=separator;%introduce separator chain string except for the first column
     37            charchain(ind_column+lsep+1:ind_column+lsep+length(textlu))=textlu;%introduce separator chain string except for the first column
     38            ind_column=ind_column+widthcolumn(jtab)+lsep;
    2739        end
    28         if ~isempty(charchain)
    29             textlu=[separator textlu];
    30         end
    31         charchain=[charchain textlu];
    3240    end
    3341    Tabchar(itab,1)={charchain};
    3442end
    35 
    36 %nb : char(Tabchar(:,jtab)) gives directly a column with the blanks filled
Note: See TracChangeset for help on using the changeset viewer.