I have a column vector of the form $\{1, 1, 2, 3, 2, 3\}^t$ and an associated matrix that has the same number of rows as the column vector, $6$, and a number of columns that is equal to the maximum of the values in the vector, $3$.
I would like to construct a matrix that has a specific value at the positions $\{1, 1\}, \{2, 1\}, \{3, 2\}, \{4,3\}, \{5,2\}, \{6, 3\}$ and zeroes everywhere else, that is, the row index corresponds to the row index in the column vector and the column index corresponds to the value at that row index.
A solution using a loop is clear to me, is there also a nifty Mathematica trick that does the job?
Flatten /@ Transpose[{Range@Length@cv, cv}]
orPartition[Riffle[Range@Length@cv, Flatten@cv] , 2]
wherecv
is your column vector will give you the desired positions list. $\endgroup$