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.

8
  • Where does x come from? gnuplot has an if (...) { } else {} construct.
    – Christoph
    Dec 3, 2013 at 19:43
  • Hi Christoph! In fact I have my own script that input 'x' as a parameter to gnuplot file.
    – Courier
    Dec 3, 2013 at 19:46
  • So what about if (x > 10000) { set xrange[*:*] } else { set xrange[10:30]}?
    – Christoph
    Dec 3, 2013 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 3, 2013 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 3, 2013 at 19:53

1 Answer 1

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]
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.