Plot Time Sensitive Data plus a fit in the same plot

2 vues (au cours des 30 derniers jours)
Tim Richter
Tim Richter le 8 Déc 2021
Commenté : Tim Richter le 8 Déc 2021
I imported two column vectors from an Excel sheet. One is called 'Thickness' and the other 'Date', which contains the Date of the measured thickness in the format: 'DD-MMM-YYY HH:MM:SS'.
I now want to achieve two things. To plot the thickness over time with a fit, and have the x-Axis displayed in the time format DD-MMM-YYY. I have no trouble with the plot, simply
works fine. Then, i want to apply a general fit to the data, to see the overall tendency of thickness over the last year. I used
fit1 = fit(DateTime,Thickness,'poly1');
to create the fitted line. 'DateTime' is the Date vector, converted with
since the fit-function does not accept datetime variables. But the big problem is: How do I plot the fit and the thickness in one plot, AND let the x-axis be displayed in DD-MMM-YYYY? The plot won't work if the fit and the data have different types. Fit in 'datenum', Date in 'Datetime', aparrently can't be plotted simultaneously. I've tried hold on/off, with no luck.
It is possible to also convert the Date into datenum, but then the x-axis labels don't help in finding correct dates.
Thanks in advance!

Réponses (1)

Yongjian Feng
Yongjian Feng le 8 Déc 2021
To show more than one plots in a figure, use
plot(Date, Thickness, '.');
hold on % this means you want more than one plots in a figure
% plot the fit here
hold off
  1 commentaire
Tim Richter
Tim Richter le 8 Déc 2021
If I do it like this:
hold on
plot(fit1,'-r') % or plot(Date,fit1,'-r') or plot(DateTime,fit1,'-r')
hold off
I get the error: 'Error evaluating CFIT function - Arguments must be numeric, char, or logical.'

Connectez-vous pour commenter.


En savoir plus sur Fit Postprocessing dans Help Center et File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by