I have this image taken from user Li-aung Yip, in his response: Is there a way to do a linear best fit from one point to another in a matrix multiple times in order to detrend a series, MatLab?

I would like to know given several time series how MatLab can do this.
Best,
Abid
Assuming that the original plots (red,green,black,blue) are of variables
a,b,c,d, each of which has a point for eacht: