Time series graph with best fit line
4 次查看(过去 30 天)
显示 更早的评论
How can I make a time series graph with year on the x axis and temperature on the y-axis. I would like to add a best fit line to show the trend. The date of the data had converted into the matlab date format. But I would like to display as year(e.g. 1999) on my x axis.
0 个评论
采纳的回答
Stephan
2018-5-1
Great,
always when i try to help people here i learn a lot ;-)
The files are attached. After converting to the correct datetime format i fitted a linear model. Not all values could be used - so the vectors have different length. Due to this the coefficients of the linear model are taken to calculate a new vector for the values of the trend line. After this operation the data can be plotted over the datetime in years.
I did this for one of the records I called "low". You can continue working according to this pattern.
I assume that these are daily maximum values and daily low values, respectively. Of course, one could also form the mean of these two values and continue to work with them - but that was not your question.
I hope I could help you.
Best regards
Stephan
2 个评论
更多回答(3 个)
Stephan
2018-4-29
编辑:Stephan
2018-4-29
Hi,
it took a little time to convert your .txt file to something matlab really could create a datetime-dataformat from ;-). File is attached. Is this correct so far? Do you start in the endof 1982 and look into the 2060's? If yes we could take the next step and think about, how the regression line could work.
The code so far is:
load('date_time_data.mat'); % file is attached . please check ;-)
subplot(2,1,1);
plot(datetime, temp);
subplot(2,1,2);
plot(datetime, temp,'+k', 'MarkerSize', 16, 'LineWidth',1.5);
ax = gca;
ax.XAxis.TickLabelFormat = 'yyyy';
Hope we are on the right way...
Best regards
Stephan
4 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!