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

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
 
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
=====vsubc=====
Conditional extraction of elements from the vector <var>x</var>.
=====Usage:=====
<code>vsubc(<var>x1</var>,<var>c</var>,<var>s1</var>,<var>x2</var>)</code>
<code>vsubc(<var>x1</var>,<var>c</var>,<var>s1</var>,<var>s2</var>,<var>x2</var>)</code>
=====Parameters:=====
;<var>x1</var>
:The input vector.
;<var>c</var>
:The condition. The following values are supported:
:<code>0</code> - select all <var>x</var>[i] where <var>x</var>[i] < <var>s1</var>
:1 - select all <var>x</var>[i] where <var>x</var>[i] > <var>s1</var>
:<code>2</code> - select all <var>x</var>[i] where <var>s1</var> < <var>x</var>[i] < <var>s2</var>
;<var>s1</var>
:A real number. See <var>c</var> for details.
;<var>s2</var>
:A real number (only used if <var>c</var><code>==2</code>). See <var>c</var> for details.
;<var>x2</var>
:<var>x2</var> is optional. If specified, the elements in <var>x2</var> are extracted based on the selected values in <var>x1</var>. <var>x2</var> must be a vector with exactly the same number of rows as <var>x1</var>.
=====Result:=====
The result is a scalar or a vector with the selected elements from <var>x1</var> (or <var>x2</var> - see <var>x2</var> for details).
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
Extract rows from a vector or matrix.
Extract rows from a vector or matrix.
;Usage: '''<code>vsubc(<var>x</var> , 0 , <var>vmin</var> {, <var>y</var> }})</code>'''
;Usage:
::'''<code>vsubc(<var>x</var> , 1 , <var>vmax</var> {, <var>y</var> }})</code>'''
:{|class="keinrahmen"
::'''<code>vsubc(<var>x</var> , 2 , <var>vmin</var>, <var>vmax</var> {, <var>y</var> }})</code>'''
|<code>vsubc(<var>x</var>, <var>c</var>, <var>v</var> {, <var>y</var>})</code> ||with ''c'' = 0, 1, 4 or 5
::'''<code>vsubc(<var>x</var> , 3 , <var>vmin</var>, <var>vmax</var> {, <var>y</var> }})</code>'''
|-
|<code>vsubc(<var>x</var>, <var>c</var>, <var>v</var><sub>1</sub>, <var>v</var><sub>2</sub> {, <var>y</var>})</code>|| with ''c'' = 2, 3, 6 or 7
|}
:;<var>x</var>: condition vector (and source vector if argument ''y'' is not supplied); must be a vector!
:;<var>x</var>: condition vector (and source vector if argument ''y'' is not supplied); must be a vector!
:;<var>vmin</var>: lower boundary; must be a scalar or a vector with the same length as ''x''
:;<var>c</var>: condition used to select values
:;<var>vmax</var>: upper boundary; must be a scalar or a vector with the same length as ''x''
:;<var>v, v<sub>1</sub>, v<sub>2</sub></var>: lower and/or upper boundary; must be a scalar or a vector with the same length as ''x''
:;<var>y</var>: optional source data; must be a vector or matrix with the same number of rows as ''x''
:;<var>y</var>: optional source data; must be a vector or matrix with the same number of rows as ''x''
;Result: A numerical object with <code>nrow(''x'')</code> columns and ''n'' rows, consisting of the rows ''o'' to ''o''+''n''-1 of the argument ''x''.
;Result: A numerical object consisting of all selected rows of the source ''y'' (or ''x'' if ''y'' is not supplied). The 2nd argument ''c'' must be a number in the range '''0''' to '''7''' and defines the condition used for the selection of the source rows.
;Description: The 2nd argument ''c'' (a number in the range 0..3) defines the condition used for the selection of the source rows.
:::{|
;* 2nd argument is '''0'''
!value of ''c'' !!row ''i'' is selected if ...
|-
|'''0''' ||<code>''x''[''i''] < ''v''</code>
|-
|'''1''' ||<code>''x''[''i''] > ''v''</code>
|-
|'''2''' ||<code>''v''<sub>1</sub> < '' ''x''[''i''] < ''v''<sub>2</sub></code>
|-
|'''3''' ||<code>''x''[i] < ''v''<sub>1</sub> or ''x''[''i''] > ''v''<sub>2</sub></code>
|-
|'''4''' ||<code>''x''[''i''] &le; ''v''</code>
|-
|'''5''' ||<code>''x''[''i''] &ge; ''v''</code>
|-
|'''6''' ||<code>''v''<sub>1</sub> &le; '' ''x''[''i''] &le; ''v''<sub>2</sub></code>
|-
|'''7''' ||<code>''x''[i] &le; ''v''<sub>1</sub> or ''x''[''i''] &ge; ''v''<sub>2</sub></code>
|}
:If a boundary ''v'' is a vector, the i-th element of the vectors ''x'' and ''v'' are compared, otherwise the element  ''x''[''i''] is compared with the number ''v''. The function failes, if no row is selected.
;See also: [[../vsubn|vsubn]], [[../limit|limit, limitlow, limithigh]], [[../select|select]]
 
[[../#Functions|<function list>]]


;See also: [[Programmer_Guide/Command_Reference/EVAL/vsubc|vsubc]], [[Programmer_Guide/Command_Reference/EVAL/select|select]],
[[Programmer_Guide/Command_Reference/EVAL/vvset|vv]]


Example:
Example:
Line 63: Line 41:
#a := eval vv(1,2,3,4,5)
#a := eval vv(1,2,3,4,5)
#b := eval vmcol($#a, vv(5,4,3,2,1))
#b := eval vmcol($#a, vv(5,4,3,2,1))
#c := vsubn($#a,3)
#c := vsubc($#a,0,3)
// -> vector: $#c = { 4 , 5 }
// -> vector: $#c = { 1 , 2 }
#d := eval vsubn($#b, 1 , 3)
#d := eval vsubc($#a,2,0,5,$#b)
// -> matrix: $#d[*,0] = { 2 , 3 , 4 },  $#d[*,1] = { 4 , 3 , 2 }
// -> matrix: $#d[*,0] = { 2 , 3 , 4 },  $#d[*,1] = { 4 , 3 , 2 }
#e := eval vsubn($#a, 2, 1)
#e := eval vsubc($#a,7,2,4)
// -> scalar: $#e = 2, this is equivalent to $#a[2]
// -> vector: $#e = { 1 , 2 , 4 , 5 }
#f := eval vsubn($#b, 2, 1)
// -> vector (!!): $#f = { 3 , 3 }, this is equivalent to $#b[2,*]
</pre>
</pre>
[[Programmer_Guide/Command_Reference/EVAL#Functions|<function list>]]

Latest revision as of 12:10, 21 April 2011

Extract rows from a vector or matrix.

Usage
vsubc(x, c, v {, y}) with c = 0, 1, 4 or 5
vsubc(x, c, v1, v2 {, y}) with c = 2, 3, 6 or 7
x
condition vector (and source vector if argument y is not supplied); must be a vector!
c
condition used to select values
v, v1, v2
lower and/or upper boundary; must be a scalar or a vector with the same length as x
y
optional source data; must be a vector or matrix with the same number of rows as x
Result
A numerical object consisting of all selected rows of the source y (or x if y is not supplied). The 2nd argument c must be a number in the range 0 to 7 and defines the condition used for the selection of the source rows.
value of c row i is selected if ...
0 x[i] < v
1 x[i] > v
2 v1 < x[i] < v2
3 x[i] < v1 or x[i] > v2
4 x[i] ≤ v
5 x[i] ≥ v
6 v1 x[i] ≤ v2
7 x[i] ≤ v1 or x[i] ≥ v2
If a boundary v is a vector, the i-th element of the vectors x and v are compared, otherwise the element x[i] is compared with the number v. The function failes, if no row is selected.
See also
vsubn, limit, limitlow, limithigh, select

<function list>


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 }

Navigation menu

Personal tools