You're subtracting the ith and jth column, which gives a whole column (3 values). Then you're trying to stuff those 3 values into a single location at B(i,j). You can't stuff 3 numbers into a position meant for one number. Not really sure what you want to do so not sure how to fix it.
For triangular matrices, see the functions tril() and triu().