MATLAB: Assign values to different ranges of columns in rows in a 2Dmatrix

array_matrix_indexmatrix_index

Hello,
Suppose I have a matrix A as follows
A = [1 2 3; 4 5 6; 7 8 9]
and an array with indexes:
i = [1 2 2]
each element in i denotes a column in a row, i.e. i(1) –> 1st column of first row in A
Is it possible (without a for loop) to set for each row, columns from 1 to the correspondent index in i to a certain value, say 0?
Thank you for your time

Best Answer

It is not entirely clear from your description what you want. If you want the entire column set to a certain value where the "i" numbers are the column numbers, then
A(:,i) = the_value;
If you mean only the diagonal elements, then
A(sub2ind(size(A),i,i)) = the_value;
If you mean something else, then we need more description (e.g., with a short example).