| OptFEM2DP1 Toolbox V1.2b3 Matlab/Octave Optimized P1-Lagrange Finite Element Method in 2D

- Main Page
- Related Pages
- Files

- File List
- File Members

All Files Functions 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
22 fprintf(fid,'\\begin{tabular}{%s}\n',ColumnFormat);
23 fprintf(fid,' %s \n',RowFormat);
24
25 % Header
26 FFormat=DataFormat{1};
27 for i=1:nC-1
28 fprintf(fid,' %s &',Header{i});
29 FFormat=sprintf('%s & %s',FFormat,DataFormat{i+1});
30 end
31 fprintf(fid,' %s ',Header{nC});
32 fprintf(fid,' \\\\ %s\n',RowHeaderFormat);
33
34 for i=1:nR
35 fprintf(fid,FFormat,Data(i,:));
36 fprintf(fid,'\\\\ %s\n',RowFormat);
37 end
38
39 fprintf(fid,'\\end{tabular}\n');
40 if (fid ~=1)
41 fclose(fid);
42 fprintf(' -> %s\n',LaTeXFilename);
43 end
44 end