Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8409 > unrolled thread

ListInterpolate and missing values

Started byMark Coleman <markspcoleman@gmail.com>
First post2012-02-09 10:35 +0000
Last post2012-02-10 10:55 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  ListInterpolate and missing values Mark Coleman <markspcoleman@gmail.com> - 2012-02-09 10:35 +0000
    Re: ListInterpolate and missing values Ray Koopman <koopman@sfu.ca> - 2012-02-10 10:55 +0000

#8409 — ListInterpolate and missing values

FromMark Coleman <markspcoleman@gmail.com>
Date2012-02-09 10:35 +0000
SubjectListInterpolate and missing values
Message-ID<jh07i4$hq6$1@smc.vnet.net>
Hi,

I'm looking for a way to linearly interpolate missing values in a
large list of numbers such that the interpolated values reflect the
size of the "gap" between non-missing values. For instance, say I have
the following list:

x={1,2,10,,12,2,6,6,,,12,22}

The list x has two gaps. A gap of size "1" at x[4], and a gap a size
"2" at x[10]-x[11]. I'm looking for a linear interpolation method such
that

x[4] = 11,

x[10]=8, x[11]=10

That is, each of the interpolated values is a constant increment
between the two surrouding non-missing values. My actually problem has
millions of such lists, where gaps are dispersed randomly (In thinking
about his more, missing endpoints could also be interpolated by
"extending" the line between the two succeeeding or preceeding
points).

I'm wondering if ListInterpolate can handle this sort of problem
directly? If not, any help would be much appreciated.

Cheers,

Mark

[toc] | [next] | [standalone]


#8447

FromRay Koopman <koopman@sfu.ca>
Date2012-02-10 10:55 +0000
Message-ID<jh2t2o$mc$1@smc.vnet.net>
In reply to#8409
On Feb 9, 2:35 am, Mark Coleman <markspcole...@gmail.com> wrote:
> Hi,
>
> I'm looking for a way to linearly interpolate missing values in a
> large list of numbers such that the interpolated values reflect the
> size of the "gap" between non-missing values. For instance, say I have
> the following list:
>
> x={1,2,10,,12,2,6,6,,,12,22}
>
> The list x has two gaps. A gap of size "1" at x[4], and a gap a size
> "2" at x[10]-x[11]. I'm looking for a linear interpolation method such
> that
>
> x[4] = 11,
>
> x[10]=8, x[11]=10
>
> That is, each of the interpolated values is a constant increment
> between the two surrouding non-missing values. My actually problem has
> millions of such lists, where gaps are dispersed randomly (In thinking
> about his more, missing endpoints could also be interpolated by
> "extending" the line between the two succeeeding or preceeding
> points).
>
> I'm wondering if ListInterpolate can handle this sort of problem
> directly? If not, any help would be much appreciated.
>
> Cheers,
>
> Mark

x = {1,2,10,,12,2,6,6,,,12,22};
p = Position[x, Null]
x[[Flatten@p]] = Interpolation[Delete[
   Transpose@{Range@Length@x,x}, p], InterpolationOrder->1] @@@ p
x

{{4},{9},{10}}
{11,8,10}
{1,2,10,11,12,2,6,6,8,10,12,22}

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web