How to set integers to values?

Hey, I want to use the stem function to plot some points based on a data set x. This data set is x[n] and consists of values 0, 0, 0, 3, 2, 1, 0, -1. I want to associate these values with integers from -4 to 4. So x[-4] is 0, x[-3] is 0, x[-1] is 3, etc. I want to do this so I can easily plot functions on my homework such as y[n] = 2x[-n], where when n=4, it corresponds to x[-4].

2 Comments

What you have tried so far, shared with us?
x = [0,0,0,3,2,1,0,1,2,3,0,1,0,0,0]
y = 2*(-x);
stem(x,y)
except this doesn't work, because the question calls for y = 2*x[-n], not y = 2*(-x[n]).

Sign in to comment.

Answers (1)

S.subs{ii}=S.subs{ii}+1;
are changed to
S.subs{ii}=S.subs{ii}+5;
and all of the places that currently subtract 1 instead subtract 5.
Needless to say, this is not recommended .
It is instead recommended that you use the stem(x,y) form instead of the stem(y) . And besides, the stem(y) form by itself would not bother to examine what was passed in to determine the lower bound if the matrix, so it would not label the axes properly even if you could index at -4 .

Tags

Asked:

on 2 Oct 2018

Commented:

on 2 Oct 2018

Community Treasure Hunt

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

Start Hunting!