How to set integers to values?
Afficher commentaires plus anciens
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 commentaires
KALYAN ACHARJYA
le 2 Oct 2018
What you have tried so far, shared with us?
Baldwin Ngo
le 2 Oct 2018
Réponses (1)
Walter Roberson
le 2 Oct 2018
You can take the source code at https://www.mathworks.com/matlabcentral/fileexchange/33301-zero-based-indexable-arrays-oop-exercise and modify it so that all of the
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 .
Catégories
En savoir plus sur Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!