0
$\begingroup$

The main issue which needs to be solved is:

Let's say I have an array with 8 numbers, e.g. [2,4,8,3,5,4,9,2] and I use them as values for my x axis in an coordinate system to draw a line. But I can only display 3 of this points. What I need to do now is do reduce the number of points (8) to 3, without manipulating the line too much - so using an average or something like that should be an option. I am NOT looking for the average of the array in a whole - I still need 3 points of the amount of 8 in total.

For an array like [2,4,2,4,2,4,2,4] and 4 numbers out of that array, I could simply use the average "3" of each pair I guess - but that's not possible if the number is uneven.

But how would I do that? Do you know any algorithms to do this? How is that process even called?

To give you some more realistic details about this issue: I have an x axis, which is 720px long and let's say I get 1000 points. Now I have to reduce this 1000 points (2 arrays, one for x and one for y values) to a maximum of 720 points.

Thought about interpolation and stuff like that, but I'm still not quite sure if this is what I am looking for.

$\endgroup$

closed as unclear what you're asking by MarcoB, user9660, Yves Klett, ubpdqn, Öskå May 28 '16 at 10:57

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ I'm not sure I follow. Something like this? en.wikipedia.org/wiki/… $\endgroup$ – Szabolcs May 25 '16 at 11:45
  • $\begingroup$ Take a look at MovingMap + Mean $\endgroup$ – Kuba May 25 '16 at 11:49
4
$\begingroup$

ArrayResample may be what you are after, as it keeps the same general shape of the original data

list1 = Sin[#] + RandomReal[0.1] & /@ Subdivide[2 π, 999];
Length@list
list2 = ArrayResample[list, 720];
Length@list2
ListLinePlot[{list1, list2}, DataRange -> {1, 1000}]
(* 1000 *)
(* 720 *)

Mathematica graphics

But if you want to do some smoothing, then MovingAverage will do the job.

MovingAverage gives a list of length Length[list]-r+1.

So if you have a list of 1000 elements you want reduced to 720 elements, then you need to give an r value of 281. But note that the new data does not cover the same range as the old data

list = Sin[#] + RandomReal[0.1] & /@ Subdivide[2 π, 999];
Length@list
list2 = MovingAverage[list, 281];
Length@list2
Show[ListPlot@list,
 ListLinePlot[list2, DataRange -> {140, 860}, PlotStyle -> Red]
 ]
(* 1000 *)
(* 720 *)

Mathematica graphics

$\endgroup$
  • $\begingroup$ Thanks for your helpful hints so that I can go further. $\endgroup$ – Christopher Wagner Jun 1 '16 at 8:44

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