You are assinging different values to A,B, and C in every iteration of the for loop. That's why you are left with the last assigned value. Also, looks like your A_I, B_I, C_I are vectors, not matrices. So no need to use A_I(i,:), just use A_I(i), maybe? What's the purpose the for loop?