vector

This page describes the BLT vector command, not the concept of a vector in general.

A BLT vector is a one-dimensional ordered set of real numbers.

Vector command in BLT

Synopsis

vector create vecName ?vecName ...? ?switches?
vector destroy vecName ?vecName ...?
vector expr expression
vector names ?pattern?

Description

Creates a vector of floating-point values. Each vector is also a Tcl command (vecName), with a Tcl array variable access to elements. Vectors support math expressions and can feed BLT graph, barchart, stripchart elements.

vector create vecName ?vecName ...? ?switches? : Create vectors. vecName may be name, name(size), name(first:last). Returns name(s).
  • -variable varName : Tcl array variable bound to vector. Empty string = none.
  • -command cmdName : Tcl command name for vector. Empty string = none.
  • -watchunset boolean : Destroy vector when its variable is unset.
vector destroy vecName ?vecName ...? : Destroy vectors, their commands and variables.
vector expr expression : Evaluate vector expression, return result as list.
vector names ?pattern? : List vectors, optionally matching glob pattern.

Vector Operations

vecName append item ?item ...? : Append vectors or lists of values to end.
vecName binread channel ?numValues? ?flags? : Read binary values from open channel. Flags: -swap, -format fmt.
vecName clear : Clear indices cached in the vector.
vecName delete index ?index ...? : Delete listed indices (or ranges first:last).
vecName dup destName : Copy vector to destName.
vecName expr expression : Evaluate expression, assign result to vector.
vecName length ?newSize? : Return length, or resize.
vecName merge vecName ?vecName ...? : Merge vectors' values into this one.
vecName normalize ?vecName? : Scale values to 0..1. Optionally store in vecName.
vecName notify keyword : Control change notification: always, never, whenidle, now, cancel, pending.
vecName offset ?value? : Get/set index offset for the vector.
vecName populate destName ?density? : Fill destName with values interpolated between this vector's points.
vecName random ?seed? : Fill with random values 0..1.
vecName range first ?last? : Return values from first to last as list.
vecName search ?-value? value ?value? : Return indices where value (or range) found.
vecName seq start ?finish? ?step? : Fill with sequence of values.
vecName set item : Set values from list, vector, or expression result.
vecName sort ?-reverse? ?vecName ...? : Sort ascending; other vectors reordered alike.
vecName split ?vecName ...? : Split into vectors (even/odd indices etc.).
vecName variable ?varName? : Get/set bound array variable.

Indexing

  • vecName(3) : single element.
  • vecName(2:5) : range.
  • vecName(min), vecName(max) : index of smallest/largest value.
  • vecName(end) : last element. vecName(++end) : append new element.

Math Functions

Usable in expr and vector expressions:

  • Element-wise: abs acos asin atan ceil cos cosh exp floor log log10 random round sin sinh sqrt tan tanh
  • Reduce to scalar: adev kurtosis length max mean median min norm prod q1 q3 sdev skew sum var
  • Vector-valued: sort

Example

vector create x y -variable ""
x seq 0 10 0.5
y expr {sin(x)}
set m [vector expr max(y)]

Related pages

In pure-Tcl, lists are most appropriate for representing vectors.