Matrix within a matrix not working inside for loop?