First of all, it's hard to get a good fit out of so little data points.
Second, your data in the code example is not a simple exponential function,
I think t is not a constant parameter, is it?
Moreover, I could be mistaken, but in the curve it looks like g and p are constants, because it's so straight, which means this is actually a linear function.
More importantly, the exponential fit works for a sum of exponentials, not a piecewise function of exponentials.
fit exponential model is that: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/197802/image.png)
and not this: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/197803/image.png)
for the later, I think you will have to map the discontinuities first (assuming you don't know their locations in advance) then fit seprately for each range
(Or if anyone knows how to do it with fit I will love to know too)
I know some people use fft or haar to find discontinuities, but if you know this is a decaying exponent, i think the simplest way is to use diff. the locations where the difference is positive, are the discontinuities. If this is an actual signal measured by some instrument and you have noise, you'll have to evaluate the noise and set some threshold to distinguish noise from discontinuities.