help-octave
[Top][All Lists]

Re: How do I print and save tables?

 From: Ron . Simonson Subject: Re: How do I print and save tables? Date: Mon, 15 Sep 2014 11:52:07 -0700 User-agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:10.0.6esrpre) Gecko/20120713 Thunderbird/10.0.6

On 09/12/2014 08:01 PM, Montgomery-Smith, Stephen wrote:

If you want to turn it into a latex file, I wouldn't use octave.  I
would use a program like perl to do it.  Octave definitely isn't an
ideal language for handling text.  On the other hand, learning perl
might be a bit of a steep learning curve, so if you ask nicely, someone
might provide a nice script for you.  (But if you are using Windows, you
will have to install perl, whereas it typically comes preinstalled with
Linux.)


I agree that octave is not the ideal tool for working with lots of
text.  awk, perl, sed, and other tools are more useful for these
kinds of tasks.  However, if you are only dealing with a few simple
strings, I will at times just do some of this stuff in octave.

For example:
\begin{octave->latex}

outfile = "myoutputfile.dat";

mydata = [0.15, 0.22, 1.2, 320, 22;
0.15, 0.22, 0.9, 293, 24;
0.15, 0.22, 1.2, 290, 26];

numrows = rows(mydata);

fpwrite = fopen(outfile, "w");

fprintf(fpwrite, "\\begin{table}[t]\n");
fprintf(fpwrite, "\\centering\n");
fprintf(fpwrite, "\\begin{tabular}{|c|c|c|c|c|}\n");
fprintf(fpwrite, "\\hline\n");

fprintf(fpwrite, "xpos (mm) & ypos (mm) & voltage (V) & temperature (K) & thickness (Angstroms)\\\\\n");
fprintf(fpwrite, "\\hline\n");

for ii = 1:numrows
fprintf(fpwrite, "%#4.3g & %#4.3g & %#5.4g & %#5.4g & %#5.4g\n",

mydata(ii,1), mydata(ii,2), mydata(ii,3), mydata(ii,4), mydata(ii,5));
endfor % ii

fprintf(fpwrite, "\\hline\n");
fprintf(fpwrite, "\\end{tabular}\n");
fprintf(fpwrite, "\\caption{Completely made up data}\n");
fprintf(fpwrite, "\\label{mytable1:myexample}\n");
fprintf(fpwrite, "\\end{table}\n");

fflush(fpwrite);
fclose(fpwrite);

\end{octave->latex}

Not pretty, but it can get you going if you do not have the
other tools available.  I suggest awk since it is pretty easy
to learn and use and it works on almost all platforms with
a rather small footprint.

Ron.



reply via email to