I'm sorry you were forced to have any kind of sexual activity.
You don't say what "excess" masturbation is to you, and I've found that there's quite a bit of difference from person to person. Some may mean that to be several times a day, or once a day, others once a week, etc.
Anytime someone has ED, I suggest ruling out anything medical as the cause. It could be a hormone issue, a heart problem, or a variety of other things.
When you get an erection when you masturbate, is it weak then? If that's what you mean, I'd for sure get things checked out as it could indicate a medical problem.
It could be anxiety - since you couldn't get the erection with the woman, you started worrying, and now there's concern that it won't happen, which causes stress, which creates this cycle of anxiety and ED.
Have you ever talked to anyone about what happened to you? If you haven't, maybe now is a good time.
Definitely get checked by your doctor. Rule out anything medical. Then talk to someone about anxiety and trauma, if you are ready to do that.