The error message is clear. I guess it occurs for this line:
This means, that Sw is ill-conditioned, such that there is no inverse of it. This is equivalent to dividing by zero. There is no "help" for this case, but the inputs do not allow this operation.
By the way, use
instead of the explicit inversion for numerical reasons. See doc inv .