MATLAB: How to use the values in a vector to use/represent the indices of another vector or matrix

indexinglogical-arraysmatrix manipulationvector

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?

Best Answer

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