Programmer Guide/Command Reference/EVAL/select: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
 
(9 intermediate revisions by 2 users not shown)
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: '''<code>select(<var>x</var>, <var>t</var>, <var>yl</var>, <var>yh</var>)</code>'''
;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
:;<var>yl</var>: result if <code>''x''[''i]'' <= ''t''{[''i'']}
:;<var>yl</var>: result if <code>''x''[''i''] &le; ''t''{[''i'']}</code>
:;<var>yh</var>: result if <code>''x''[''i]'' > ''t''{[''i'']}
:;<var>yh</var>: result if <code>''x''[''i''] > ''t''{[''i'']}</code>
::''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 ''x''[''i]'' <= ''t''{[''i'']} and  
::<code>''r''[i] = ''yl''{[''i'']}</code> if <code>''x''[''i''] &le; ''t''{[''i'']}</code> and  
::<code>''r''[i] = ''yh''{[''i'']}</code> if ''x''[''i]'' > ''t''{[''i'']}
::<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: [[Programmer_Guide/Command_Reference/EVAL/vsubn|vsubn]], [[Programmer_Guide/Command_Reference/EVAL/select|vsubc]], [[Programmer_Guide/Command_Reference/EVAL/vvset|vv]]
;See also: [[../vsubc|vsubc]], [[../limit|limit, limitlow, limithigh]]
 
[[../#Functions|<function list>]]


Example:
Example:
<pre>
<pre>
#a := eval vv(1,2,3,4,5)
#a := eval vv(1,2,3,4,5,4,3,2,1)
#b := eval vmcol($#a, vv(5,4,3,2,1))
#b := eval fill(9,0,1)
#c := vsubc($#a,0,3)
#c := eval select($#a,3,0,$#a)
// -> vector: $#c = { 1 , 2 }
// -> $#c = { 0 , 0 , 0 , 4 , 5 , 4 , 0 , 0 , 0 }  
#d := eval vsubc($#a,2,0,5,$#b)
#d := eval select($#a, $#b , $#b , $#a)
// -> matrix: $#d[*,0] = { 2 , 3 , 4 }, $#d[*,1] = { 4 , 3 , 2 }
// -> $#d = { 1 , 2 , 3 , 4 , 5 , 5 , 6 , 7 , 8 }
#e := eval vsubc($#a,7,2,4)
#e := eval select($#b%2, 0, $#b, -1)
// -> vector: $#e = { 1 , 2 , 4 , 5 }
// -> $#d = { 0 , -1 , 2 , -1 , 4 , -1 , 6 , -1 , 8 }
</pre>
</pre>
[[Programmer_Guide/Command_Reference/EVAL#Functions|<function list>]]

Latest revision as of 15:46, 1 October 2015

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]} if x[i] ≤ t{[i]} and
r[i] = yh{[i]} if x[i] > t{[i]}
The result r has the same length as x.
See also
vsubc, limit, limitlow, limithigh

<function list>

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 }

Navigation menu

Personal tools