If you are having fine erections during masturbation and morning erections then the cause of erectile dysfunction seems psychological in nature. You should go for a clinical examination and blood test to check for testosterone level etc for diagnosis. You should avoid alcohol and smoking, take healthy food, do sensual exercise, counseling done by a psychologist. You can do some regular exercise in form of yoga, shed weight and have a proper sleep.
It is very difficult to precisely confirm a diagnosis without examination and investigations and the answer is based on the medical information provided. For exact diagnosis, you are requested to consult your doctor. I sincerely hope that helps. Take care and please do keep me posted on how you are doing.