Filter löschen
Filter löschen

how can I get the square wave in matlab

2 Ansichten (letzte 30 Tage)
ocsse
ocsse am 10 Mär. 2018
Bearbeitet: Star Strider am 11 Mär. 2018
when the y-axis = 1, -5 < t < -1
when the y-axis = -1, -1 < t < 3
t = linspace(-5, 3, samples+1);
f = square(t);
figure(1)
plot(t, f)
thank you in advance

Akzeptierte Antwort

Star Strider
Star Strider am 10 Mär. 2018
Bearbeitet: Star Strider am 11 Mär. 2018
Try this:
samples = 100;
t = linspace(-5, 3, samples+1);
f = 1*((t >= -5) & (t <= -1)) + (-1)*((t > -1) & (t <= 3));
figure(1)
plot(t, f)
axis([-5.5 3.5 -1.1 1.1])
EDIT Changed ‘t’ and axis limits to reflect edited limits (about 04:00 UCT 11 Mar 2018) in original Question.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by