Isolate the linear segment of data/graph
8 ビュー (過去 30 日間)
古いコメントを表示
I am trying to create a script where I plot data and I need to find the slope of the most linear segment of the data/graph. Any ideas on how I can do that for a script whose data will vary for each trial.

3 件のコメント
Adam Danz
2021 年 8 月 30 日
I'd compute the slope using gradient as Star Strider recommended. If you plot the results you'll see a relatively straight line at some high value and will be precipitously fall off at the point where the original data starts to call off. To quantitatively determine the endpoint of the 'straight' line, you could take the 2nd derivative (gradient of the gradient) to locate the first spike that crosses a threhold you set.
採用された回答
Star Strider
2021 年 8 月 30 日
One reasonably straightforward way to determine the slope of a curve is to use the gradient function.
For example, the gradient of the hyperbolic tangent function:
x = linspace(-4, 4, 500);
f = tanh(x);
dfdx = gradient(f) ./ gradient(x);
figure
plot(x, f)
hold on
plot(x, dfdx)
hold off
grid
legend('Function','Derivative', 'Location','best')
Then use the gradient result to determine what parts of the curve have the characteristics you’re interested in.
.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spline Postprocessing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

