Composite xrange in gnuplot
I have a periodic system and I want to fit some data for this system to a function, but I want to constrain to a range. Usually, if your range is from x_min to x_max this can be achieved with fit [x_min:x_max] f(x) "data" via a,b,c,.... However, because my system is periodic, I want to constrain to a range that contains a segment at the end of the array of x values and also at the beginning. That is, if x values are given within the interval [0:L], I want to include in the fit both [0:x_max] and [x_min:L], where in this case x_max < x_min. How can this be done?
How about this? fit [min1:max2] f(x) "data" u 1:($1 <= max1 || $1 >= min2 ? $2 : 1/0) via a,b,c,... That is, make use of the [:] for the outer range. I'm not sure it's much nicer but it is a little bit shorter. Alternatively, you could use set table in the following way: set table 'newdata' p [0:x_max] 'data' p [x_min:L] 'data' unset table fit f(x) 'newdata' via a,b,c,... Basically this writes a new file containing only the data between the two ranges. Arguably nicer, definitely not shorter!
I figured an ugly way to do it, but if anyone comes up with a nicer way I will accept that as the answer. Imagine the two ranges where you want to fit (or plot) the data are given by [min1:max1] and [min2:max2], then using a conditional fit and the "ignore" function 1/0 you can do the following: fit f(x) "data" u 1:( ($1 >= min1 && $1 <= max1) || ($1 >= min2 && $1 <= max2) ? $2 : 1/0) via a,b,c,... That is, if x is within the first interval or the second one, then use y as a value for the fit, otherwise ignore those data points. This approach should also work with plot, but I think something like a composite range operator [min1:max1 && min2:max2] (which does not work) would be more desirable.
Auto-scale setting the window too small GNUPLOT
Gnuplot Data and Parametric
gnuplot: can a function be plotted with vectors?
Tab completion not working correctly in gnuplot
gnuplot with lines is not working
Add guiding lines over pm3d map in Gnuplot
How to plot a smooth surface in GNUplot?
Two plots on the same graph
Plot contours from one graph into another in Gnuplot
gnuplot: silent error reading (non-standard form of) scientific format numbers
gnuplot plotting against time-difference
grid lines are changed in multiplot if lines styles of y column is changed
Gnuplot: How to make scatter plots with transparent points
Gnuplot - How do not plot a piece of line for non-contiguous date/time
GNUPLOT: stats gives wrong results on loop
How to plot 3d scalar field from a dataset using gnuplot