This is just a possibility, but I've heard it mentioned often before and see from my view point of what I've learned in classes that it is possible. Bluntly speaking, one possibility of why you would go limp during sex, asides from anxiety, stress, alcohol, etc, is that your penis basically got used to ejaculating via masturbation. Frequent masturbation could cause this because the penis requires the same degree of stimulus that you get in masturbation to ejaculate. A vagina, feeling very different from what you've been used to for so often, doesn't quite do it for you.
As I said, this is only what I've heard, but can see it is logical (has to do with nerve ending and action potentials).
I and anybody else commenting are most likely not doctors, so don't take what we say 100% seriously, but my only suggestion that I can think of is, stop masturbating for a significant amount of time and just keep trying to get off with girls.