Fix matrix dimensions