how can I get the square wave in matlab
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Star Strider
le 10 Mar 2018
Modifié(e) : Star Strider
le 11 Mar 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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!