I've been trying to use fitlm as a way of finding the steepest linear portion of a graph but cannot get it to work correctly. Perhaps there is a better way I could be finding this out?
Essentially I have data (stress and strain) which looks like the following:
I'm trying to use Matlab to automatically find the steepest linear portion of the graph. This is what I have been trying so far using the fitlm function.
R=0;for x = 100:size(strain) fitlm(strain(10:x),stress(10:x)); if ans.Rsquared.Ordinary > R R=ans.Rsquared.Ordinary; index=x; endend
I can get the code to go along the data and find out where the r-squared value seems to fit best and identify a linear region of the data, but how can I get Matlab to identify the steepest linear region?
This is the output of plotting from the start of the data to the index point:
Best Answer