finding the slope of each segement in a fitted curve

13 ビュー (過去 30 日間)
Salma fathi
Salma fathi 2022 年 4 月 13 日
コメント済み: Salma fathi 2022 年 4 月 14 日
having the following plot,
Is there a method that would allow me to find the slope of each segment in this plot or at least, how I cann retrieve the x , y coordinates for the points on the plot so I can use them to find the slope?
attached is the data I am fitting, the x coordinate is GDALT variable and the y coordinate is the NE variabel. I used the curve fitting toolbox to generate this plot.
  3 件のコメント
Akira Agata
Akira Agata 2022 年 4 月 14 日
It might be better to smoothen your data before calculating slope for each point, like:
T = readtable('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/963595/t1.txt');
idx = isnan(T.NE);
T(idx, :) = [];
x = linspace(T.GDALT(1), T.GDALT(end));
y = interp1(T.GDALT, T.NE, x, 'spline');
figure
plot(T.GDALT, T.NE, 'o-')
hold on
plot(x, y)
legend({'Original', 'Smoothed'})
Salma fathi
Salma fathi 2022 年 4 月 14 日
編集済み: Salma fathi 2022 年 4 月 14 日
Thank you for your reply, I believe I can do that also by using interpolating via 'cubic spline' instead of 'linear' in the curve fitting toolbox and it would give the same result right?
But I am still not sure how this will help me in finding the slope at the indicated points in the plot...

サインインしてコメントする。

採用された回答

Chunru
Chunru 2022 年 4 月 14 日
T = readtable('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/963595/t1.txt');
idx = isnan(T.NE);
T(idx, :) = [];
x = T.GDALT;
y = T.NE;
plot(x, y, 'o-')
% The slope for each segment
slope = diff(y)./diff(x)
slope = 15×1
1.0e+10 * 0.1733 0.4733 1.0267 1.1600 0.8067 0.3600 -0.1067 -0.3467 -0.4267 -0.4267
  1 件のコメント
Salma fathi
Salma fathi 2022 年 4 月 14 日
Thank you for the help.

サインインしてコメントする。

その他の回答 (1 件)

Akira Agata
Akira Agata 2022 年 4 月 14 日
By applying interpolation, you can decrease and, as a result, the deviation will be more accurate.
The following is an example.
BTW, you don't need to use Curve Fitting Toolbox for interpolation. The function interp1 is in the basic MATLAB.
T = readtable('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/963595/t1.txt');
idx = isnan(T.NE);
T(idx, :) = [];
x = linspace(T.GDALT(1), T.GDALT(end));
y = interp1(T.GDALT, T.NE, x, 'spline');
dy = diff(y)/uniquetol(diff(x));
figure
yyaxis left
plot(T.GDALT, T.NE, 'bo')
hold on
plot(x, y, 'b-')
xlabel('NE')
ylabel('GDALT')
yyaxis right
plot(x(1:end-1),dy)
ylabel('\Delta GDALT / \Delta NE')
legend({'Original', 'Smoothed', 'Slope'})
  1 件のコメント
Salma fathi
Salma fathi 2022 年 4 月 14 日
Thank you for the great explanation, I have a better understanding now. Much appreciated.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by