Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on a utility to analyze a set of data. I want to process the data with a sliding window, in such a way that there is an output associated with each sample of data.

To start, I have a list of data: MyData

I've defined the following utility function to pull 10 consecutive samples of data from MyData starting at an arbitrary location within MyData.

EvalWin[x_] := Take[MyData, {x, x + 9}];

This works.

Now lets say I have a processing function that sums the 10 samples.

ProcData[x_] := Total[EvalWin[x]];

This also works.

The problem comes if I attempt to use ProcData[] as an argument to a built in Mathematica function such as Plot.

For example if I attempt to plot ProcData[] for a set of 100 samples...

Plot[ProcData[x], {x, 10, 110}]

The Plot function blows up due to recursion.

Are there ways to control how built in functions handle data to avoid recursive blow up, or is there a more Mathematica friendly way to accomplish this kind of data manipulation?

share|improve this question
Your problem isn't recursion, it's the fact that array indices have to be positive integers and Plot assumes a continuous variable. – Jens Feb 11 '13 at 4:56
By the way, in case you're really interested in something like what your example does, maybe take a look at MovingAverage – Jens Feb 11 '13 at 5:10

Use DiscretePlot[] instead for integer-valued functions:

ProcData[x_Integer] := Sum[MyData[[k]], {k, x, x + 9}]

DiscretePlot[ProcData[x], {x, 10, 110, 1}]
share|improve this answer
This (+1), or ListPlot seem to be the most appropriate solutions. Or one could stick with Plot and replace ProcData[x] with ProcData[Floor[x]]. – Jens Feb 11 '13 at 4:54
So the issue is really in the need to establish that I am working with an integer. Thanks. – Bruce Zenone Feb 11 '13 at 13:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.