Hi Chanelle,
To add trendlines to multiple plots simultaneously you can use Curve Fitter App using which you can interactively fit curves and surfaces to data and view plots. You can also compare multiple fits simultaneously using regression, interpolation, smoothing, and custom equations.
You can refer the following image for better understanding:
Alternatively, you can also add trendlines to multiple plots simultaneously using “polyfit” and “polyval” functions. "polyfit" fits a polynomial to your data points, while "polyval" evaluates this polynomial across a specified range for plotting purposes. This produces a visual representation that showcases both the original data points and the corresponding fitted polynomial curve, facilitating straightforward comparison.
You can refer the following code snippet:
plot(x1, yfit1, 'k-', 'LineWidth', 2);
Similarly, this can be done for other subplots.
You can refer the below attached output obtained from an example data:
To know more about Curve Fitter App,” polyfit” and “polyval” , you can go through the following documentations:
- https://www.mathworks.com/help/curvefit/curvefitter-app.html
- https://www.mathworks.com/help/curvefit/interactive-fit-comparison.html
- https://www.mathworks.com/help/matlab/ref/polyfit.html
- https://www.mathworks.com/help/matlab/ref/polyval.html
Hope this helps!