【发布时间】:2020-02-04 13:39:38
【问题描述】:
我想建立一个从点 a 开始的斜坡函数 并在 b 点结束。 [a,b]
我已经构建了一个斜坡函数的代码,它从 0 开始并在点 b.[0,b] 结束。
这是代码:
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
但我想定义区间 [a,b] 中定义的斜坡函数的新代码。并且在区间外的值为 0。
我已经尝试过这段代码。但它修改了所有的斜坡函数。
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
【问题讨论】: