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

From STX Wiki
Jump to navigationJump to search
m (1 revision: Initial import)
No edit summary
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
=====select=====
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>'''
:;<var>x</var>: condition vector; must be a vector!
:;<var>t</var>: threshold
:;<var>yl</var>: result if <code>''x''[''i]'' <= ''t''{[''i'']}
:;<var>yh</var>: result if <code>''x''[''i]'' > ''t''{[''i'']}
::''t'', ''yl'' and ''yh'' must be numbers or vectors with the same length as ''x''
;Result: A vector ''r'' with ...
::<code>''r''[i] = ''yl''{[''i'']}</code> if ''x''[''i]'' <= ''t''{[''i'']} and
::<code>''r''[i] = ''yh''{[''i'']}</code> if ''x''[''i]'' > ''t''{[''i'']}
:The result r has the same length as ''x''.


The <code>select</code> subcommand performs a conditional assignment. The arguments <var>x</var> and <var>t</var> are compared and the result <var>yl</var> (<var>x</var> <= <var>t</var>) or <var>yh</var> (<var>x</var> > <var>t</var>) is assigned. The result type is the same as <var>x</var>. This is a subcommand of the <code>[[Programmer Guide/Command Reference/EVAL/EVAL|EVAL]]</code> command.
;See also: [[Programmer_Guide/Command_Reference/EVAL/vsubn|vsubn]], [[Programmer_Guide/Command_Reference/EVAL/select|vsubc]], [[Programmer_Guide/Command_Reference/EVAL/vvset|vv]]


{|
Example:
|-
<pre>
|Usage:
#a := eval vv(1,2,3,4,5)
|select(x, <var>t</var>, <var>y1</var>, <var>yh</var>)
#b := eval vmcol($#a, vv(5,4,3,2,1))
|-
#c := vsubc($#a,0,3)
|Parameters:
// -> vector: $#c = { 1 , 2 }
|{|
#d := eval vsubc($#a,2,0,5,$#b)
|-
// -> matrix: $#d[*,0] = { 2 , 3 , 4 },  $#d[*,1] = { 4 , 3 , 2 }
|<var>x</var>
#e := eval vsubc($#a,7,2,4)
|The input (vector)
// -> vector: $#e = { 1 , 2 , 4 , 5 }
|-
</pre>
|t
|The threshold value (vector or scalar)
|-
|y1
|The result if x[i] <= <var>t</var>|<var>t</var>[i] (vector or scalar)
|-
|yh
|The result if x[i] > <var>t</var>|<var>t</var>[i] (vector or scalar)
|}


 
[[Programmer_Guide/Command_Reference/EVAL#Functions|<function list>]]
|  
|-
|Return Type:
|The same as x.
|}

Revision as of 13:11, 6 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]}
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
vsubn, vsubc, vv

Example:

#a := eval vv(1,2,3,4,5)
#b := eval vmcol($#a, vv(5,4,3,2,1))
#c := vsubc($#a,0,3)
// -> vector: $#c = { 1 , 2 }
#d := eval vsubc($#a,2,0,5,$#b)
// -> matrix: $#d[*,0] = { 2 , 3 , 4 },  $#d[*,1] = { 4 , 3 , 2 }
#e := eval vsubc($#a,7,2,4)
// -> vector: $#e = { 1 , 2 , 4 , 5 }

<function list>

Navigation menu

Personal tools