Thanks for the question. It is uncommon for men to have erectile dysfunction(ED) suddenly. ED may happen with younger persons like you. There are many causes for this sudden happening, mostly due to intake of alcohol or smoking too. Sometimes stress or performance anxiety can also cause ED. It was a good idea about resting for sex and masturbating for some time. If this problem of erection continuous it would be better to consult a doctor about intake of drugs relating to ED.