I have a big matrix of numerical data, let assume here for practicity a small matrix
a=[1 1 1;
1 1 1]
Then I have a vector of indices
b=[4;
2]
My goal is to "apply" vector b
to a
, row by row, in such a way to nullify all the items of the i-th row of a
which are falling in the columns whose indices are greater than the i-th element of b
, when possible.
Therefore my desired output would be:
c=some_smart_indexing_operation(a,b) %this is pseudo-code of course
c=[1 1 1;
1 0 0]
Let me comment the results row by row:
on the first row,
b
's first element is 4: havinga
only 3 colums no element is nullifyon the second tow,
b
's second element is 2: I should nullify the second and the third element of this row.
I could perform such an operation with a for
loop by I was wondering if I could get the same result applying some smart indexing operation or applying some vectorial native functions.