MATLAB Answers


How do i find points where slope is zero.

Eirikur Bernharðsson さんによって質問されました 2019 年 10 月 14 日 22:07
最新アクティビティ Star Strider
さんによって コメントされました 2019 年 10 月 15 日 11:58
I dealing with data from an experiment and i need to find local equivalents or the points where slope is zero.
I tried it in the code as you can see in graph (the red circles), I could find a couple, but the rest dont have the slope exactly zero.
So anyone know if its possible to find the top point or the equivalents.
gogn = xlsread(fullfile('C:\Users\ebben\Dropbox\HR\Eðlisfræði\Verklegt\Top','TOP_gogn.xlsx'));
angle = gogn(:,3); % Exstracting data from excel doc
time = gogn(:,4);
scl = find(angle==min(angle));
time = time(scl:numel(time)); % deleting data in beginning thats not important
angle = angle(scl:numel(angle));
stilling = angle(numel(angle)); % Adjusting to fit x-axis = 0
angle = angle + abs(stilling);
plot(time,angle,'Linewidth',1.5) % plotting and designing graph
hold on
dx_time1 = mean(diff(time)); % trying to find where slope is zero
dy_angle = gradient(angle,dx_time1);
slope_angle = dy_angle(1)
for i=1:numel(time)
slope_angle = dy_angle(i);
if slope_angle == 0
for i=1:numel(vec)
% for lykkja sem plottar upp punktana á graf
hold on

  0 件のコメント

サインイン to comment.


1 件の回答

Star Strider
回答者: Star Strider
2019 年 10 月 14 日 22:37

If you want to use the gradient function to find the inflection points, and since you are dealing with finite-precision values, one approach would be to use linspace and interp1 to create a much higher resolution ‘time’ vector, and then interpolate the ‘angle’ vector to it.
Also, using a tolerance rather than a specific value here:
if slope_angle <= 1E-4
or something similar, might be more appropriate.
However, since you want to find the maxima and minima, the easiest approach would be to use the findpeaks function on the signal and its negative value (to find the minima), or the islocalmax and islocalmin functions to do the same.
It depends on what approach you want to take, and the constraints of your data and data processing.

  2 件のコメント

Eirikur Bernharðsson 2019 年 10 月 15 日 10:08
MVP. didnt know about the findpeaks function.
Star Strider
2019 年 10 月 15 日 11:58
Neither did I a few years ago!

サインイン to comment.

Translated by