![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/545077/image.png)
Locating point on x-axis where the slope is decreasing
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tessa Kol
am 10 Mär. 2021
Kommentiert: Star Strider
am 10 Mär. 2021
Dear all,
I used the following code to plot the angle over time:
figure
hold on
grid on
plot(Time, theta,'linewidth',1.5)
xlabel('Time [s]','FontWeight','bold')
ylabel('\theta [deg]','FontWeight','bold')
xlim([0 round(Time(end))])
legend('Opening angle','Location','northeast')
title('Opening angle')
The resulting graph is shown below. I want to index at what time the slope is decreasing. How can I do that?
The variables Time and theta to plot this graph can be found in the data.mat file.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/544902/image.jpeg)
0 Kommentare
Akzeptierte Antwort
Star Strider
am 10 Mär. 2021
A reasonably robust way is to use the ischange function:
D = load('data.mat');
Time = D.Time;
theta = D.theta;
[TF,m,b] = ischange(theta, 'linear', 'Threshold',5);
chgpts = [find(TF); m(TF); b(TF)].';
chgidx = find(chgpts(:,2)<0,1);
figure
plot(Time, theta,'linewidth',1.5)
hold on
plot(Time(chgpts(chgidx(:,1))), theta(chgpts(chgidx(:,1))), 'xr')
hold off
grid on
xlabel('Time [s]','FontWeight','bold')
ylabel('\theta [deg]','FontWeight','bold')
xlim([0 round(Time(end))])
legend('Opening angle','Location','northeast')
title('Opening angle')
producing:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/545077/image.png)
The ‘Time’ value is then:
ChangePointTime = Time(chgpts(chgidx(:,1)));
that here is 6.01 seconds.
4 Kommentare
Weitere Antworten (1)
Sargondjani
am 10 Mär. 2021
Bascially you want to get the index when the change in theta becomes negative:
dtheta = diff(theta);
index = find(dtheta<0,1);%the 1 refers to the first entry where the statement is true
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!