Create a long rectangular signal with a function handle

2 Ansichten (letzte 30 Tage)
AEW
AEW am 20 Apr. 2022
Bearbeitet: AEW am 20 Apr. 2022
I was wondering if there is a quick way to create a rectangular signal during 20 sec for example, with a function handle. I tried the following command which requires you to do it for every step.
Thanks.
u=@(t) double((0<=t & t<0.5) + ...
(1<=t & t<1.5) + ...
(2<=t & t<2.5)) .* 1;

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 20 Apr. 2022
Bearbeitet: Bruno Luong am 20 Apr. 2022
myfun = @(t) mod(t,1)<=0.5;
ezplot(myfun, 0, 20)
  4 Kommentare
Bruno Luong
Bruno Luong am 20 Apr. 2022
fun=@(x) ppval(mkpp(0:0.25:1,[1; 0; -1; 0]),mod(x,1))
fun = function_handle with value:
@(x)ppval(mkpp(0:0.25:1,[1;0;-1;0]),mod(x,1))
ezplot(fun,0,3)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Sam Chak
Sam Chak am 20 Apr. 2022
Second opinion!
fcn = @(t) (sign(sin(2*pi*t)) + 1)/2;
ezplot(fcn, 0, 5)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by