2

For a lack of a better way to describe it, I want to apply a modulo to an rrange expression in Gnuplot 5.0 in order to ensure that the max is "rounded" to the nearest 10 units. I think that I'm on the right track, but am curious whether there is a more elegant method to accomplish this. For example, this yields what I want:

max_range = int(STATS_max)

if (max_range == 0) {
    max_range = 1
}

while (max_range % 10 != 0) {
    max_range = (max_range + 1)
}

So, for example, a STATS_max value of 13.2 yields a max_range of 20.

Thanks in advance, Dave

1
  • Just as a follow-up to @Christoph's excellent answer below. For my purposes, I still need to retain the code segment above that ensures that max_range does not equal zero. Applying ceil() to zero yields zero which, while accurate, is an illegal value for range max value. Error: "Can't plot with an empty y range!" Commented Jul 21, 2015 at 19:52

1 Answer 1

3

First divide your max_range by 10, apply the ceil function (takes the next larger integer value) and multiply the result by 10:

max_range = ceil(STATS_max / 10.0) * 10.0
Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant. Thanks very much Christoph!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.