23

How to perform control sequences under Gnuplot please? I need to make something like

if (x == nan)
  set xrange[]

else
  set xrange[10:30]

I tried something like

( x > 100000 ) ?  (set xrange[]) : (set xrange[10:30])

... buth without success! I spent hours trying to solve this!! Any help please? At worst I can create a shell script an manage this, but I think there should be some control sequences to fix this.

Courier
  • 920
  • 2
  • 11
  • 36
  • Where does `x` come from? gnuplot has an `if (...) { } else {}` construct. – Christoph Dec 03 '13 at 19:43
  • Hi Christoph! In fact I have my own script that input 'x' as a parameter to gnuplot file. – Courier Dec 03 '13 at 19:46
  • So what about `if (x > 10000) { set xrange[*:*] } else { set xrange[10:30]}`? – Christoph Dec 03 '13 at 19:50
  • As you suggest, I tried this 'if(2==3){ set xrange[] } else {set xrange[10:30]}', but it does not work. – Courier Dec 03 '13 at 19:51
  • What do you mean with 'doesn't work'? For me it works fine, but requires version 4.6. But `set xrange []` does nothing, to use autoscaling use e.g.`set xrange[*:*]` or `set autoscale x`. – Christoph Dec 03 '13 at 19:53
  • The issue is not with 'set range[]'. I already tried it. The issue is with the manner Am using 'if'. P.S Am using Gnuplot 4.4 – Courier Dec 03 '13 at 19:53
  • `xrange[*:*]` does not work for me. By "Does not work" I mean I have an error message. The code breaks. – Courier Dec 03 '13 at 19:54
  • With 4.4.4 the following works for me: `x = 2; if (x == 3) set autoscale x; else set xrange [10:30];` – Christoph Dec 03 '13 at 19:59

1 Answers1

35

For gnuplot 4.4.4 the if statement must be on a single line:

if (x > 10000) set autoscale x; else set xrange [10:30]

or use \ to continue on the next line.

if (x > 10000) \
    set autoscale x; \
else \
    set xrange [10:30]

Since 4.6.0 gnuplot can use brackets to delimit the branches:

if (x > 10000) {
    set autoscale x
} else {
    set xrange [10:30]
}
Christoph
  • 47,569
  • 8
  • 87
  • 187