Gnuplot: plotting differences between two matrices

I have two files file1.dat

and file2.dat

, each containing a matrix (say F1 and F2 respectively) that are consistent in size (i.e. they are matrices m x n

). I know how to use gnuplot to plot any of these (for example splot "file1.dat" matrix

), but how can I instruct gnuplot to plot F1-F2?

+3


source to share


2 answers


Unfortunately (as far as I know) there is no way to print information from multiple files using gnuplot. The solution is to write a simple script (in your favorite language) that takes two files as input and writes the difference as output ... Then you could do:

splot "<myscript file1.dat file2.dat" matrix ...

      



I'm sure that with enough coaxing, using set table

shell magic as well, I could come up with hacks to do what you want (having gnuplot output multiple datafiles, issuing shell commands to insert datafiles together ...), but in in the end, writing your own script would be a much cleaner solution.

+1


source


Here is a working example using the awk bit in gnuplot.

set terminal postscript enhanced colour
set output 'matrixdiff.eps'

unset key 
splot "<awk 'NR==FNR{for(i=1;i<=NF;++i)a[FNR,i]=$i;next}{for(i=1;i<=NF;++i)$i=a[FNR,i]-$i;print}' mat1 mat2" matrix

      



mat1

and mat2

are the matrix files you want to build. The awk script is from here .

+1


source







All Articles