Command Reference : Function Reference : Function Reference: U
  
 
@unitvector
 
Extracts column from an identity matrix.
Syntax: @unitvector(n1, n2)
n1: integer
n2: integer
Return: vector
Creates an n1 element vector with a 1 in the n2-th element, and 0 elsewhere.
Examples
vector v1 = @unitvector(8, 5)
creates an 8 element vector with a 1 in the fifth element and 0 for the other 7 elements.
vector v2 = @unitvector(8, 3)
matrix h = @mnrnd(8, 8)
matrix hselect1 = h * v2
matrix hselect2 = h.@col(3)
create HSELECT1 and HSELECT2 into which we extract column 3 from the matrix H.
Cross-references
See also @identity, @ones, and @zeros.