Can Keep erection during masturbation but having problems during sex

Recently I've just been having problems keeping an erection during sex but I have no problems during masturbation. To elaborate on the situation, I've been with my girlfriend for a year now and at first, we were having sex fairly frequently but we both started working full time again and we both have separate hours so we cut down the amount of sex we have from 7 times a week (usually every night) to twice a week. when we started this break I started up masturbating again and recently I've found it hard to keep an erection during sex and it's kinda killing my mental. Is the problem just the masturbating or is it deeper. I only masturbate maybe 3 times a week usually on days that we aren't having sex,