How to plot a piecewise in MATLAB?

3 vues (au cours des 30 derniers jours)
Siddharth Garg
Siddharth Garg le 8 Sep 2019
I have this piecewise function and I have to plot this discrete signal using the stem function. This is what I wrote:
And this is the error I am getting:
What is it that I am doing wrong?
  1 commentaire
Siddharth Garg
Siddharth Garg le 8 Sep 2019
Note- In the 10th line, it should be: x<=-1

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 8 Sep 2019
I prefer the anonymous function approach:
x = @(n) n.*((0<=n) & (n<=8)) + 1*((-4<=n) & (n<=-1));
n = -10:12;
figure
stem(n, x(n))
grid

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by