I am using fit as described in https://www.mathworks.com/help/curvefit/fit.html to fit and plot a timestamp (in seconds from a base epoch) vs. data along with the fit and confidence values. I can't copy/paste results unforunately so this will have to be descriptive.
% timestamp = 1d array of doubles: seconds elapsed since 1/1/1970; ~1.57E9 sec
% data = 1d array of doubles: one data point per timestamp point; ~1E-10
curvefit = fit(timestamp, data, 'poly1', 'normalize','on'); % Generate fit
plot(curvefit, timestamp, data, 'o', 'predfunc') ; % Generate plot showing data, fit, and confidence bounds
For the plot, I'd like the x-axis to be dates. I can convert the timestamp to a datestamp using
datestamp = datetime(timestamp, 'ConvertFrom', 'epochtime', 'Epoch', epoch) ; % with epoch defined elsewhere
I tried getting the axis limits for the gcf and updating:
lim = axis;axis( [datestamp(1) datestamp(end) lim(3) lim(4)] ); % Change x-axis, keep y-axis
The error message says all inputs must be datetimes, date/time character vectors, or date/time strings.
xlim([datestamp(1) datestamp(end)])
The error message says that xlim requires numeric inputs.
Interestingly, I can generate a data vs. datestamp plot:
plot(datestamp, data,'o')
but this does not have the benefit of autogenerated fits, confidence bounds, and legends.
I'm missing something simple…
Best Answer