MATLAB: Storing multiple matrices from a loop

for loopmatrices

I have a 5×5 matrix and what the program is supposed to do is to run through the columns(i) and whenever it finds a row in the ith column that is zero. It makes the whole row zero [0 0 0 0 0]. And store the different matrices for every(i) column in a matrix DBIBC(i). So far the loop only runs for the DBIBC(1) and stores only that in the array.
rw finds the rows in the column that are zero.
Please help me.
BIBC = [1 1 1 1 1;0 1 1 1 1;0 0 1 1 0;0 0 0 1 0;0 0 0 0 1] ;
DBIBC = BIBC;
N=length(BIBC);
for i=1:N
rw = find(DBIBC(:,i)==0)
DBIBC(rw,:)= 0
DBIBC(i)
B{i} = DBIBC;
end

Best Answer

Hi,
You need to re-inizialize the temporary matrix DBIBC for each iteration, if not the first iteration makes 2-5 rows 0 and thats all....
BIBC = [1 1 1 1 1;0 1 1 1 1;0 0 1 1 0;0 0 0 1 0;0 0 0 0 1] ;
N=length(BIBC);
for i=1:N
DBIBC = BIBC;
rw = find(DBIBC(:,i)==0)
DBIBC(rw,:)= 0
DBIBC(i)
B{i} = DBIBC;
end