fit the y=mx+c in time series

2 views (last 30 days)
Nurul Ain Basirah Zakaria
Nurul Ain Basirah Zakaria on 28 Mar 2021
Commented: Star Strider on 28 Mar 2021
Hi. I have 420x1 data of time series.
How can I fit y=mx+c line in the plotting?

Answers (1)

Star Strider
Star Strider on 28 Mar 2021
That could be a challenge.
One option is to use mldivide,\:
dt = datetime('now')+days(1:10);
T1 = table(dt(:), rand(10,1)+(0.1:0.1:1).');
B = [day(T1.Var1) ones(size(T1.Var1))] \ T1.Var2;
LinFit = [day(T1.Var1) ones(size(T1.Var1))] * B;
figure
plot(T1.Var1, T1.Var2, 'p')
hold on
plot(T1.Var1, LinFit, '-r')
hold off
grid
Depending on the time series, the results could appear a bit unusual.
.
  4 Comments
Nurul Ain Basirah Zakaria
Nurul Ain Basirah Zakaria on 28 Mar 2021
ya im sorry. its not the threshold ;) thank you very much!
Star Strider
Star Strider on 28 Mar 2021
My pleasure!
Did I provide a meaningful solution?
If not, what do you want to do?

Sign in to comment.

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!