- matlab indexing starts at 1
- how is x(n) defined for n > 4
- how is y(n-1) defined?
Can someone explain how to plot y[n]
2 views (last 30 days)
Show older comments
I'm very new to MATLAB and I need someone to explain how to plot y[n] over the range -2<n<6. These are the equations I am given:
x[-1]=1
x[0]=2
x[1]=2
x[2]=1
x[3]=4
y[n]=x[n]+y[n-1};
-2<n<6
I have tried but my problem is that I can't use negative indexes in arrays
2 Comments
Jos (10584)
on 25 Feb 2015
Answers (1)
dpb
on 25 Feb 2015
It's not defined unless you define it and again, Matlab arrays are 1-based (and, unfortunately, inflexible in that).
To handle a case such as this where the axis is negative, you must keep the indices as 1:N but instead of using the value of the timestep or increment as the index, keep a second vector of time values as well as the y vector.
t=-2:6; % the time steps (or use _n_ if prefer)
Now evaluate y for each value of t, then
plot(t,y)
0 Comments
See Also
Categories
Find more on Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!