StepInterp
Release: |
4.6 • 5.0 • 5.1 • 5.2 • 5.3 • 5.4 • 6.0 • 6.1 • 6.2 • 6.3 • 6.4 • 6.5 |
---|
StepInterp is a lookup function which finds which interval along «xi» a value «x» lands in, and returns the corresponding «yi» for that interval.
StepInterp(xi, yi, x, i, use)
Given arrays of coordinates «xi» and «yi», indexed by «i», it returns the «yi» value corresponding to the smallest value in «xi» with xi ≥ x
. Thus, it returns a step function, with risers at each value of «xi». If optional parameter «use» is 'Left'
, it returns the y value corresponding to the largest value of «xi» ≤ x, and if «use» is 'Nearest'
it returns the «yi» value corresponding to the «xi» that is closest to «x». «xi», «yi», and «x» do not need to be numbers. The values in «xi» must be in increasing order. If «xi» is itself a simple index, «yi» must be indexed by «xi», and parameter «i» may be omitted. Otherwise, «i» must be a common index of «xi» and «yi». «x» may be a scalar or array. If «x» is less than the smallest (and first) value in «xi» (x < xi[@i = 1]
), it returns that smallest value. Similarly, if «x» is larger than the last (largest) value in «xi» (x > xi[@i = IndexLength(i)]
), it returns that largest value.
If «x» is a single value, the result of StepInterp is an array indexed by all indexes of «yi» except «xi»’s index. If «x» is an array, the result of Stepinterp is also indexed by the indexes of «x».
StepInterp is similar to Subscript(u1, i, u2); however, Subscript selects based on the index value being equal to «x», while StepInterp selects based on the array value being greater than or equal to «x».
StepInterp can be used to perform table lookup.
Examples
The following examples use User Guide Examples.
To see the values in Car_prices
corresponding to Years >= 2007.5
:
StepInterp(Years, Car_prices, 2007.5, Years) →
Car_type ▶ VW Honda BMW 19 22 30
Here v is a list of two values:
StepInterp(Years, Car_prices, [2007, 2008], Years) →
VW Honda BMW 2007 18K 20K 28K 2008 19K 22K 30K
Optional Parameters
«i»
Specifies the common index of «xi» and «yi». You can omit this, if «xi» is itself an index of «yi».
«use»
(new to Analytica 5.3) The optional «use» parameter can be any one the following:
'Left'
: Find the closest value in «xi» to the left of «x».'NearestL'
: Find the closest value in «xi» to «x». Break ties by using the one to the left.'Nearest'
: Same as'NearestR'
'NearestR'
: Find the closest value in «xi» to «x». Break ties by using the one to the right.'Right'
: (default) Find the closest value in «xi» to the right of «x».
The two graphs interpolate from the same set of (xi, yi) points, with different settings for «use».
use:'Right' (default) |
use:'Left' |
See Also
- The User Group Webinar Intro to Step Interpolation recording.
- LinearInterp
- CubicInterp
- MonoCubicInterp
- SubIndex -- used to find an exact match in the body cells of an array.
- Subscript -- used to find an exact match in the index values.
- User Guide Examples / Array Function Examples.ana / Interpolation Functions Module
Enable comment auto-refresher