OptFEM3DP1 Toolbox: common/PrintDataInLatexTabular.m Source File

| OptFEM3DP1 Toolbox 20130618_070730 Matlab/Octave Optimized P1-Lagrange Finite Element Method in 3D

- Main Page
- Related Pages
- Files

- File List
- File Members

All Files Functions Variables Pages
PrintDataInLatexTabular.m
Go to the documentation of this file.
1 function PrintDataInLatexTabular(Data,Header,DataFormat,ColumnFormat,RowFormat,RowHeaderFormat,LaTeXFilename)
2 % DataFormat={'$%d$','$%d$','%.3f','%.3f','%.3f'}
3 % ColumnFormat='|r|r||*{3}{c|}'
4 % RowFormat='\hline';
5 % RowHeaderFormat='\hline \hline';
6 % Header={'$N$','$n_q$','Matlab','Octave','FreeFEM++'}
7 % Data array
8 % Copyright:
9 % See \ref license
10
11 [nR,nCG]=size(Data);
12 nC=length(Header);
13 if isempty(LaTeXFilename)
14 fid=1;
15 else
16 fid=fopen(LaTeXFilename,'w');
17 if (fid == -1)
18 error(['Cannot open file ',LaTeXFilename]);
19 end
20 end
21 fprintf(fid,'%%\\documentclass[]{article}\n%%\\begin{document}\n');
22
23
24 fprintf(fid,'\\begin{tabular}{%s}\n',ColumnFormat);
25 fprintf(fid,' %s \n',RowFormat);
26
27 % Header
28 FFormat=DataFormat{1};
29 for i=1:nC-1
30 fprintf(fid,' %s &',Header{i});
31 FFormat=sprintf('%s & %s',FFormat,DataFormat{i+1});
32 end
33 fprintf(fid,' %s ',Header{nC});
34 fprintf(fid,' \\\\ %s\n',RowHeaderFormat);
35
36 for i=1:nR
37 fprintf(fid,FFormat,Data(i,:));
38 fprintf(fid,'\\\\ %s\n',RowFormat);
39 end
40
41 fprintf(fid,'\\end{tabular}\n');
42 fprintf(fid,'%%\\end{document}');
43 if (fid ~=1)
44 fclose(fid);
45 fprintf(' -> %s\n',LaTeXFilename);
46 end
47 end