Hi, friend! The ode you provided is a 2nd order ode. Follow the code you will know how to solve this ode. But at first, since both the mass m and the stiffness K is positive, the equation should be modified as:
Then the code is
odefun = @(t,x, K, m, g)[x(2); -K/m*x(1)+g];
[t, x] = ode45(@(t,x)odefun(t, x, K, m, g), tspan, x0);
xlabel('t'); ylabel('x or dx/dt')