Can someone explain how to plot y[n]
显示 更早的评论
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 个评论
Jos (10584)
2015-2-25
- matlab indexing starts at 1
- how is x(n) defined for n > 4
- how is y(n-1) defined?
Matthew Guiller
2015-2-25
回答(1 个)
dpb
2015-2-25
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)
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!