How to identify negative slope from plot data?

5 views (last 30 days)
So I'm trying to do some lap simulation work and I want to isolate the braking zones (negative slope) from a velocity vs. time data plot. I was thinking I could get it to identify mins/maxs but I would still need to identify if the region is sloped downward. How can I get the program to recognize that?

Answers (2)

KSSV
KSSV on 2 Dec 2022
t = linspace(0,2*pi) ;
y = sin(t) ;
m = [0 diff(y)./diff(t)] ;
plot(t,y) ;
hold on
plot(t(m<0),y(m<0),'+r')
plot(t(m>=0),y(m>=0),'+g')
legend('sine','negative slope','positive slope')

Sam Chak
Sam Chak on 2 Dec 2022
This is just a basic idea for identifying the region of negative slope. Generally, the numerical differentiation of the velocity data is obtained.
t = linspace(0, 180, 1801);
V = sin(2*pi/180*t); % velocity data
dV = gradient(V, t)/(2*pi/180); % numerical differentiation of V: cos(2*pi/180*t)
plot(t, [V' dV'], 'linewidth', 1.5), grid on,
ylim([-1.5 1.5]), yline(0, '--')
xlabel('t'), legend('V', 'dV', '')
xtval = 0:15:180; xticks(xtval)
idx = find(dV < 0);
slopeStart = t(idx(1))
slopeStart = 45.1000
slopeEnd = t(idx(end))
slopeEnd = 134.9000
The region of negative slope lies between and .

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!