0

Suppose there is a vector

 v = [1 2 3];

in MATLAB. I am doing a signal processing operation which needs a non causal signal, so what I basically require is the vector to start from -1 ,i.e, I need to do this

v[-1] = 1
v[0] = 2
v[1] = 3

unlike the usual MATLAB indexing i.e

v[1] = 1
v[2] = 2
v[3] = 3

Is there a way to do this? Can someone write a matlab function to accomplish this?

1 Answers1

3

(a) that is not usual MATLAB indexing, you don't use [] brackets to index you use () parenthesis. (b) no that is not possible but you could simulate the behaviour using an intermediary translation function so something like:

f = @(x)x+2

and now

v(f(-1)) == v(1) == 1
v(f(0)) == v(2) == 2
v(f(1)) == v(3) == 3

This answer by Gnovice shows you a way to change the base indexing if you really really want to. But honestly, it would be a pretty terrible idea unless you had an extremely compelling reason to do so. Just stick with the 1-base indexing.

Community
  • 1
  • 1
Dan
  • 45,079
  • 17
  • 88
  • 157