Main Content

ind2vec

(To be removed) Convert indices to vectors

ind2vec will be removed in a future release. For more information, see Transition Legacy Neural Network Code to dlnetwork Workflows.

For advice on updating your code, see Version History.

Description

vec = ind2vec(ind) takes a row vector of indices, ind, and returns a sparse matrix of vectors, vec, containing a 1 in the row of the index they represent, as indicated by ind.

ind2vec and vec2ind allow indices to be represented either by themselves, or as vectors containing a 1 in the row of the index they represent.

example

vec = ind2vec(ind,N) returns an N-by-M sparse matrix, where N can be equal to or greater than the maximum index.

Examples

collapse all

This example shows how to convert indices to vector representation using the ind2vec function.

Define four indices and then convert them to vector representation.

ind = [1 3 2 3];
vec = ind2vec(ind)
vec =
   (1,1)        1
   (3,2)        1
   (2,3)        1
   (3,4)        1

Input Arguments

collapse all

Indices, specified as a row vector.

Number of rows of the output matrix, specified as a scalar.

Output Arguments

collapse all

Vector representation of the indices, returned as an N-by-M sparse matrix.

Version History

Introduced before R2006a

collapse all