Thank for asking. I can understand the distress you are through. It appears that you are facing difficulties with getting aroused during sex with your partner. While masturbating, because you are in control of your stimulation and you are not dependent on your partner, erections are better. If you are using pornography while masturbating, it may further complicate your problem as there is a high possibility pornography dependence. Generally, porn use helps in getting aroused, as there is no porn access during sex, you may face difficulties with getting aroused.
Next Steps
I would suggest you to correct your method of masturbation, Stop pornography use, and learn more about sexual hygiene. For specific instructions on management, you can consult with me directly here on practo.
Health Tips
It is treatable.