How to make a ramp function that start in point a and finish in point b. [a,b]. And with value 0 outside the interval

조회 수: 11 (최근 30일)
I want to build a ramp function that start from point a
and finish in point b. [a,b]
I have constructed a code of a ramp functon that starts from 0 and finish in point b.[0,b].
this is the code:
hold on
b =2 % time in wich the ramp finish
a=1 %time in which the ramp start
t = [0:0.01:15]'; %timespan of the ramp function
for impAmp = [3 5 10] . %height of the ramp
function
rampOn = @(t) t<=b;
ramp =@(t) t.*impAmp.*rampOn(t);
plot(t,ramp(t))
end
But I want to define a new code of the ramp function defined in the interval [a,b]. And a value of 0 outside the interval.
I have tried this code. But it modified all the ramp function.
hold on
b =2 % time in wich the ramp finish
a=1 %time in which the ramp start
t = [0:0.01:15]';%timespan of the ramp function
for impAmp = [3 5 10]%height of the ramp function
rampOn = @(t) a<t<=b;
ramp =@(t) t.*impAmp.*rampOn(t);
plot(t,ramp(t))
end

답변 (1개)

Siriniharika Katukam
Siriniharika Katukam 2019년 10월 10일
Hi
A small modification in the code you defined for the interval [a,b].
Using this line would yield you the expected result.
rampOn = @(t) t>=a & t<=b;

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by