How can I use the values in a vector to use/represent the indices of another vector or matrix?

Suppose, I have a vector vec_indices = [10; 14; 78; 2; 67; ...; ..;]. And I have another logical vector vec_log of size 67 x 1 (67 rows, 1 column).
Let's initialize vec_log as vec_log = zeros(67,1);
I want to use the values of vec_indices, i.e, extract values 10, 14, 72 and use them as INDICES of vec_log i.e. use vec_log(10), vec_log(14),.. and set vec_log(10) = 1, vec_log(14) = 1 etc.
How do I achieve this in Matlab?

 Respuesta aceptada

Like this:
vec_indices = [10 14 78 2 67 100];
vec_long = zeros(100,1);
vec_long(vec_indices) = 1;

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.

Preguntada:

el 20 de Oct. de 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by