How to find derivative of CSV data plot?

1 回表示 (過去 30 日間)
jasper kansiime
jasper kansiime 2018 年 9 月 28 日
コメント済み: Star Strider 2018 年 9 月 30 日
I have a csv file with uniform points but i would like to write MATLAB code for obtain the derivative of the plotted function(unknown) with time. How can i do this?
if true
% code
end

採用された回答

Star Strider
Star Strider 2018 年 9 月 28 日
It is easiest to use the gradient (link) function:
[D,S,R] = xlsread('Uniform_points.csv');
t = D(:,1);
f = D(:,2);
dt = mean(diff(t));
df = gradient(f,dt);
figure
subplot(2,1,1)
plot(t, f)
grid
title(S{2},'Interpreter','none')
xlabel(S{1})
subplot(2,1,2)
plot(t, df)
grid
title(['d(',S{2},')/dt'],'Interpreter','none')
xlabel(S{1})
  6 件のコメント
jasper kansiime
jasper kansiime 2018 年 9 月 30 日
Thanks for the discussion link.It clarified things alot.I have another question
In the above code you have" plot(t, f)" where "t" represents time axis. How can i scale the current time axis(0-1second) into an X-axis from(0- 0.4seconds) in steps of 0.04 seconds?
Star Strider
Star Strider 2018 年 9 月 30 日
To simply alter the plot x-tick labels, this works:
t_new = 0:0.04:0.4;
figure
plot(t, f)
xt = get(gca, 'XTick');
xtv = linspace(min(xt), max(xt), numel(t_new));
set(gca, 'XTick', xtv, 'XTickLabel',t_new)
I generalised it, so it is a bit more complicated than it needs to be for the current values. It will work for other ‘t_new’ vectors without further modification.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by