add length function to matrix