Fix wrong loop bound in makematrix()