MATLAB: How to set value in a matrix

set value in a matrix

I have a double matrix 4×5 matrix
A=[11 12 13 14 15;
21 22 23 24 25;
31 32 33 34 35;
41 42 43 44 45],
B=[3 0 2 4 1]
B indicates to set all the rows of B[i] in A(from row 1 to that position) to 0.
C = [0 12 0 0 0;
0 22 0 0 25;
0 32 33 0 35;
41 42 43 0 45]
Thanks

Best Answer

for i = 1:numel(B)
A(1:B(i),i) = 0;
end
Related Question