# Mapping arrays to use negative indexes

• Jun 13th 2009, 01:19 PM
n4cag
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.
• Jun 14th 2009, 04:04 AM
CaptainBlack
Quote:

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
• Jun 14th 2009, 06:51 AM
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....
• Jun 14th 2009, 09:28 AM
CaptainBlack
Quote:

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
• Jun 14th 2009, 09:44 AM
n4cag
I hate sounding like a newbie with Matlab but how do I call my values of Dn into the array?
• Jun 14th 2009, 12:05 PM
CaptainBlack
Quote:

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