rbmatlab 0.10.01
|
00001 function print_datatable(fname, title, values, blocksize) 00002 % function print_datatable(fname, title, values, blocksize) 00003 % 00004 % print a matrix in a tabulator separated table stored in file 'fname'. This 00005 % can be used by all pgfplots commandos in LaTeX. 00006 % 00007 % arguments: 00008 % 'fname': file name of file where the table is stored 00009 % 'title': vector of column titles 00010 % 'values': matrix whose rows are written to the table 00011 % 'blocksize': separate blocksize values with a new line in each column, 00012 % needed for patch plots 00013 % 00014 00015 if nargin < 4 00016 blocksize = size(values,2); 00017 end 00018 00019 numblocks = size(values,2)/blocksize; 00020 00021 assert(numblocks-floor(numblocks)==0); 00022 00023 fid=fopen(fname,'w'); 00024 00025 assert(length(title) == size(values, 1)); 00026 00027 fpstring = [repmat('%s\t', 1, length(title)), '\n']; 00028 fprintf(fid, fpstring, title{:}); 00029 fpstring2 = [repmat('%e\t', 1, length(title)), '\n']; 00030 for i=1:numblocks 00031 fprintf(fid, fpstring2, values(:,(i-1)*blocksize+(1:blocksize))); 00032 fprintf(fid, '\n'); 00033 end 00034 00035 fclose(fid);