Plot Time Sensitive Data plus a fit in the same plot
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
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
plot(Date,Thickness,'.')
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
datenum(Date)
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!
0 Commenti
Risposte (1)
Yongjian Feng
il 8 Dic 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
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!