Search code examples
if-statementsumgnuplot

Check if vector or column/row of *.dat is filled with zero values in gnuplot


In gnuplot, I need to find out if a whole column of my data file is filled with zero values (maybe by summoning up the elements?).

I just found a way to add columns in a plot, but not the column itself. I'd like to write something like

if(data(:,1)==zeros) ...

or:

if(sum(data(:,1))==0) ...

How do I address this column outside of "using 1:2 .."? Is there a short way to check this or is the sum neccessary?


Solution

  • You can you the stats function

    $data <<EOD
    1 2 0
    2 4 0
    3 3 0
    3 5 0
    EOD
    
    stats $data us 3
    print STATS_sum
    

    Another more secure way to check, whether nozero values are present, is (remember -1 and 1 could cancel out in the sum)

    any = 0
    fit a $data us 1:(any=any|($3!=0),$1) via a
    print any