How to model a ramp input with two slopes and saturation at zero?
Show older comments
Hello,
I am working on a model which I should define an input as following:
- Start time: 0
- A ramp input with slope of 0.1 up to t=10s;
- Continuing with another ramp input with slope of -0.5 after t=10s and saturation at zero.
- No negative values for amplitude and the run time=50s.
I was wodering how it is possible to model this input data using for/while loop in MATLAB!
Any assistance is highly appreciated!
Answers (1)
Les Beckham
on 22 Mar 2022
Edited: Les Beckham
on 22 Mar 2022
One approach (no loops necessary)
t=0:0.1:50;
y = zeros(size(t));
y(t<10) = 0.1 * t(t<10);
y(t>=10) = 1 - 0.5 * (t(t>=10) - 10);
y(y<0) = 0;
plot(t,y, 'linewidth', 2)
grid on
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!