title: How to average multiple table files with different x and y values
body: <p>I got some table files containing the same measuring result but due to little differences the data points got different <em>x</em> and <em>y</em> values. But I need an average across all six files. Here are two (shortened) example files:</p>
  
  <pre><code># file1.dat
    9.840000000000000E+00  1.680000000000000E+02
    9.840071206052514E+00  1.730000000000000E+02
    9.840142412105029E+00  1.630000000000000E+02
    9.840213618157543E+00  1.730000000000000E+02
    9.840284824210057E+00  1.690000000000000E+02
    9.840356030262573E+00  1.720000000000000E+02
    9.840427236315087E+00  1.660000000000000E+02
    9.840498442367601E+00  1.750000000000000E+02
    9.840569648420116E+00  1.650000000000000E+02
    9.840640854472630E+00  1.720000000000000E+02
  </code></pre>
  
  <p></p>
  
  <pre><code># file2.dat
    9.840000000000000E+00  1.720000000000000E+02
    9.840071016422547E+00  1.760000000000000E+02
    9.840142032845096E+00  1.610000000000000E+02
    9.840213049267643E+00  1.530000000000000E+02
    9.840284065690192E+00  1.590000000000000E+02
    9.840355082112739E+00  1.590000000000000E+02
    9.840426098535286E+00  1.690000000000000E+02
    9.840497114957834E+00  1.790000000000000E+02
    9.840568131380381E+00  1.680000000000000E+02
    9.840639147802928E+00  1.620000000000000E+02
  </code></pre>
  
  <p>[and four more similar files …]</p>
  
  <p>If I plot them all with <code>gnuplot</code> but each table as an own curve I get this<br>
  <img src="https://i.stack.imgur.com/D1YUI.png" alt="gnuplot"></p>
  
  <p>But I need a single curve showing the average of all six tables.</p>
  
  <p>I tried <code>join</code> but I get an empty file as the result and I Guess it won’t work because the first column (<em>x</em> values) doesn’t contain the same values in each file. Trying to do the summation in <code>gnuplot</code> with <code>plot data1 u 1:2 + data2 u 1:2</code> fails too.</p>
  
  <p>I found <a href="https://stackoverflow.com/q/7218201/1018250">merging multiple data files to plot in a single graph</a> but it doesn’t help to only merge the files.</p>
  
  <hr>
  
  <p>I’m using Mac OS X but have access to an Ubuntu to, so if there are any tool to do that …</p>
  
  <hr>
  
  <p>The new ouptut of the script</p>
  
  <pre><code>&gt; AVDEBUG=1 octave -qf avfiles.m messung3.dat messung4.dat
  warning: ================
  warning: processing file: messung3.dat
  warning: size of the matrix in the file: 2248      3
  warning: min(x): 0.000000e+00
  warning: max(x): 0.000000e+00
  warning: min(y): 9.840000e+00
  warning: max(y): 1.000000e+01
  warning: ================
  warning: processing file: messung4.dat
  warning: size of the matrix in the file: 2254      3
  warning: min(x): 0.000000e+00
  warning: max(x): 0.000000e+00
  warning: min(y): 9.840000e+00
  warning: max(y): 1.000000e+01
  warning: yp is undefined at 2248 points
  </code></pre>
  
  <p>If you like you can download my data files from <a href="http://tweh.de/texsx/data-files-avarage.zip" rel="nofollow noreferrer">here (tweh.de/texsx/data-files-avarage.zip)</a>. The avarage should be made out of all files.</p>