use apply matrix