Programmer Guide/Command Reference/EVAL/select: Difference between revisions
From STX Wiki
< Programmer Guide | Command Reference | EVAL
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:{{SUBPAGENAME}}}} | {{DISPLAYTITLE:{{SUBPAGENAME}}}} | ||
Conditional merge of selected elements of two vectors and/or scalars. | Conditional merge of selected elements of two vectors and/or scalars. | ||
;Usage: | ;Usage: <code>select(<var>x</var>, <var>t</var>, <var>yl</var>, <var>yh</var>)</code> | ||
:;<var>x</var>: condition vector; must be a vector! | :;<var>x</var>: condition vector; must be a vector! | ||
:;<var>t</var>: threshold | :;<var>t</var>: threshold | ||
Line 8: | Line 8: | ||
:Note: ''t'', ''yl'' and ''yh'' must be numbers or vectors with the same length as ''x'' | :Note: ''t'', ''yl'' and ''yh'' must be numbers or vectors with the same length as ''x'' | ||
;Result: A vector ''r'' with ... | ;Result: A vector ''r'' with ... | ||
::<code>''r''[i] = ''yl''{[''i'']}</code> if <code>''x''[''i''] | ::<code>''r''[i] = ''yl''{[''i'']}</code> if <code>''x''[''i''] ≤ ''t''{[''i'']}</code> and | ||
::<code>''r''[i] = ''yh''{[''i'']}</code> if <code>''x''[''i''] > ''t''{[''i'']}</code> | ::<code>''r''[i] = ''yh''{[''i'']}</code> if <code>''x''[''i''] > ''t''{[''i'']}</code> | ||
:The result r has the same length as ''x''. | :The result r has the same length as ''x''. | ||
;See also: [[ | ;See also: [[../vsubc|vsubc]], [[../limit|limit, limitlow, limithigh]] | ||
Example: | Example: | ||
Line 26: | Line 26: | ||
</pre> | </pre> | ||
[[ | [[../#Functions|<function list>]] |
Revision as of 11:46, 21 April 2011
Conditional merge of selected elements of two vectors and/or scalars.
- Usage
select(x, t, yl, yh)
- x
- condition vector; must be a vector!
- t
- threshold
- yl
- result if
x[i] <= t{[i]}
- yh
- result if
x[i] > t{[i]}
- Note: t, yl and yh must be numbers or vectors with the same length as x
- Result
- A vector r with ...
r[i] = yl{[i]}
ifx[i] ≤ t{[i]}
andr[i] = yh{[i]}
ifx[i] > t{[i]}
- The result r has the same length as x.
- See also
- vsubc, limit, limitlow, limithigh
Example:
#a := eval vv(1,2,3,4,5,4,3,2,1) #b := eval fill(9,0,1) #c := eval select($#a,3,0,$#a) // -> $#c = { 0 , 0 , 0 , 4 , 5 , 4 , 0 , 0 , 0 } #d := eval select($#a, $#b , $#b , $#a) // -> $#d = { 1 , 2 , 3 , 4 , 5 , 5 , 6 , 7 , 8 } #e := eval select($#b%2, 0, $#b, -1) // -> $#d = { 0 , -1 , 2 , -1 , 4 , -1 , 6 , -1 , 8 }