# Thread: Mapping arrays to use negative indexes

1. ## Mapping arrays to use negative indexes

For an assignement in my Continuous Time Signals class, we were asked to calculate the fourier series of a given x(t). The problem I'm running into is we are asked to calculate the Dn in my m-file from -10 to 10 (course Matlab cannot handle negative indices and 0 since the numerical values of Dn are stored in an array). Is there any kind of solution that I could use to get aorund this to make it calculate from -10 to 0?

Thank you a lot.

Attached is my m-file with the necessary functions. The main m-file is called Prob2. Particularly the end where plotting of Dn is where I'm mainly talking about.

2. Originally Posted by n4cag
For an assignement in my Continuous Time Signals class, we were asked to calculate the fourier series of a given x(t). The problem I'm running into is we are asked to calculate the Dn in my m-file from -10 to 10 (course Matlab cannot handle negative indices and 0 since the numerical values of Dn are stored in an array). Is there any kind of solution that I could use to get aorund this to make it calculate from -10 to 0?

Thank you a lot.

Attached is my m-file with the necessary functions. The main m-file is called Prob2. Particularly the end where plotting of Dn is where I'm mainly talking about.
DArry=zeros(1,21)
offset=11;

Now when you require a reference to Dn you use DArry(n+offset)

CB

3. Using this still gives me problems since I've changed where my references of Dn are to DArry(n+offset). Maybe I'm just implementing this wrong?

??? Index exceeds matrix dimensions.

Error in ==> problem_2test at 70
[nnd' DArry(n+offset).']

Also since now I've implemented in right I believe, my matrixes are just 0....

4. Originally Posted by n4cag
Using this still gives me problems since I've changed where my references of Dn are to DArry(n+offset). Maybe I'm just implementing this wrong?

??? Index exceeds matrix dimensions.

Error in ==> problem_2test at 70
[nnd' DArry(n+offset).']

Also since now I've implemented in right I believe, my matrixes are just 0....
Yes, that is just a declaration and how to access the correct components, you still have to fill the array with the appropriate values.

CB

5. I hate sounding like a newbie with Matlab but how do I call my values of Dn into the array?

6. Originally Posted by n4cag
I hate sounding like a newbie with Matlab but how do I call my values of Dn into the array?
Suppose you could index arrays as you want, then how would you calculate the coefficients?

CB