フィルターのクリア

How to derive and plot derive for a set of data with non linear x axis?

5 ビュー (過去 30 日間)
Youssif Youssif
Youssif Youssif 2022 年 10 月 27 日
コメント済み: Star Strider 2022 年 10 月 27 日
Hello, I have a 54x2 table for x axis and y axis. The x axis is data is non linear ( for example the first three points are 20327,20328,20329, and the fourth point is 22516, then 22517,22518,25832...) How can I plot the data and derive and plot the derivtive without linearly interpolation (so it does not fill or connect the missing points in the x axis)?

回答 (1 件)

Star Strider
Star Strider 2022 年 10 月 27 日
I have no idea what the data are.
Calculationg the numerical derivative is straightforward with the gradient function —
x = sort(rand(1,20));
y = rand(size(x));
figure
plot(x, y)
grid
xlabel('x')
ylabel('y')
title('Data')
dydx = gradient(y) ./ gradient(x);
figure
plot(x, dydx)
grid
xlabel('x')
ylabel('$\frac{dy}{dx}$', 'Interpreter','latex')
title('Derivative')
The independent variable data do not need to be evenly-spaced.
.
  2 件のコメント
Youssif Youssif
Youssif Youssif 2022 年 10 月 27 日
Heres an picture of the data, you can see that the X data is not linear, I was looking to plot it and its derivative with the data being linearly interpolated (filling in gaps where there is no data)
Star Strider
Star Strider 2022 年 10 月 27 日
I cannot do anything with an image of data.
The approach to ‘filling in gaps where there is no data’ is going to be a bit difficult, and likely depends on how you want to interpolate the ‘missing’ values.
One approach —
x = sort(rand(1,20));
y = rand(size(x));
figure
plot(x, y)
grid
xlabel('x')
ylabel('y')
title('Data')
xq = linspace(min(x), max(x), 150);
yq = interp1(x, y, xq, 'makima'); % Choose The Appropriate Interpolation Method For Your Data
figure
plot(xq, yq)
grid
xlabel('x')
ylabel('y')
title('interpolated Data')
dydx = gradient(yq) ./ gradient(xq);
figure
plot(xq, dydx)
grid
xlabel('x')
ylabel('$\frac{dy}{dx}$', 'Interpreter','latex')
title('Derivative of Interpolated Data')
See the documentation on interp1 for details and for different interpolationo methods.
.

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

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by