Loop data in both x and y direction, and do linear fit of each y at each x
5 Comments
Hi Yang,
I will help you guide to resolve your problem. First, define the two matrices matrix1 and matrix2 with random values for demonstration purposes, initialize a slope_matrix of size 96x150 to store the slopes. Then, use nested loops, we iterate over each time point and each data point column in matrix 2. For each iteration, you need to fit a linear model using fitlm to find the slope (a) for the data points at that time point. Then, the slope value is extracted from the model and stored in the corresponding position in the slope_matrix. Finally, the slope_matrix containing all the slopes is displayed. I just ran this code in Matlab to obtain a slope matrix (96x150) that represents the slopes of the linear fits for each data point at every time point. Please see attached results.

If you have further questions, please let me know.
Accepted Answer
More Answers (1)
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!