Home > utility > tableWrite.m

tableWrite

PURPOSE ^

tableWrite: Write a table with tab-separated fields

SYNOPSIS ^

function tableWrite(table, file)

DESCRIPTION ^

 tableWrite: Write a table with tab-separated fields
    Usage: table=tableWrite(table, file)

    For example:
        table=tableRead('table01.txt', 1, {'id', 'word', 'count'});
        outFile=[tempname, '.txt'];
        fprintf('Write structure to %s\n', outFile);
        tableWrite(table, outFile);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function tableWrite(table, file)
0002 % tableWrite: Write a table with tab-separated fields
0003 %    Usage: table=tableWrite(table, file)
0004 %
0005 %    For example:
0006 %        table=tableRead('table01.txt', 1, {'id', 'word', 'count'});
0007 %        outFile=[tempname, '.txt'];
0008 %        fprintf('Write structure to %s\n', outFile);
0009 %        tableWrite(table, outFile);
0010 
0011 %    Roger Jang, 20060806, 20071009
0012 
0013 colNames=fieldnames(table);
0014 fid=fopen(file, 'w');
0015 for i=1:length(table)
0016     for j=1:length(colNames)
0017         if j==1
0018             fprintf(fid, '%s', getfield(table, {i}, colNames{j}));
0019         else
0020             fprintf(fid, '\t%s', getfield(table, {i}, colNames{j}));
0021         end
0022     end
0023     fprintf(fid, '\r\n');
0024 end
0025 fclose(fid);

Generated on Tue 01-Jun-2010 09:50:34 by m2html © 2003