Locating point on x-axis where the slope is decreasing

조회 수: 2 (최근 30일)
Tessa Kol
Tessa Kol 2021년 3월 10일
댓글: Star Strider 2021년 3월 10일
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.

채택된 답변

Star Strider
Star Strider 2021년 3월 10일
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:
The ‘Time’ value is then:
ChangePointTime = Time(chgpts(chgidx(:,1)));
that here is 6.01 seconds.
  댓글 수: 4
Tessa Kol
Tessa Kol 2021년 3월 10일
Thank you so much for the code and explanation!
Star Strider
Star Strider 2021년 3월 10일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sargondjani
Sargondjani 2021년 3월 10일
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

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by