If you can reach erection, but only for a short period of time, then the reasons could be following:
1. You gave away your power and it immediately had negative effect to your erection. In the beginning you showed initiative, seduced her, acted according to your own sexual feelings and instincts, but then you suddenly stopped and started to play by the “rules”. By example, you undressed her, got an erection from looking at her and touching her naked body, felt the strong urge to roughly f**k her, bet then suddenly thought that it wouldn’t be nice, therefore you decided to give her romantic kiss, to cuddle her gently, to say some nice words. And then everything went wrong……because nice/romantic sex is boring sex……..and nice sex weakens erection………. there is no place for romance in sex….. of course, if you are in serious relationships then romance is necessary in everyday situations and before sex……but when you are having sex you only have to follow your sexual instincts….. and your only guide must be your own inner feelings about the next sexual action, which will give you the biggest pleasure…….....and you have to do it.......…..and not think about will it look nice from the perspective of the romantic girl or general understanding of what is beautiful and "right" sex.......
2. If you have at least once experienced the loss of erection during sex, then you will be afraid that it can happen again. The fear has huge power, but you can overcome it. Again, by following your true desires, as described above.
3. The anatomy of each girl is different. By example, with one girl you will have very good stimulus in doggystyle, but with other girl it may be that you feel almost nothing or even feel pain. With each partner you have to find poses, which work best for you. And even if you have lost erection, don’t despair. Have a little break, calm down and start everything over.
And always trust your sexual instincts and let them be your guide....if you will try to have sex guided by your mind or "next logical move" then don't be surprised that you will continue to lose erection during sex....
Unfortunately it takes sometimes years to recover from the betrayal - 4 years in my case, you may have to just live with the loneliness for a while for your mind to get straightened out - ED is not in the equation - it's a mental thing that needs time to heal itself
Since you say you are fine during masturbation, I would eliminate the list of physical issues. The first thing to evaluate is why masturbation is successful. If it is porn then there is your problem. Remove individual porn and do not masturbate for several days prior to a date. Porn is not typical bedroom and gradually your brain requires that type stimulation.
If porn is not involved, examine your fantasies and what turns you on. Try bringing some of that into the bedroom. If all else fails try Viagra a few times. Often it will get you back into the groove without continuing to take it.
If you are having sex just for the sake of sex, you should abstain until you meet the person you are really attracted to. Not only sexually but mentally as well. Someone you can be open with and be yourself, not hiding parts of your life because they do/might not approve.