Skip to main content
added 398 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

TimeSeries provides a fairly direct approach to this:

data = Import["https://pastebin.com/raw/QCAKwZ2P", "Package"];

dat1 = Select[data, 60 <= First[#] <= 140 &];
dat2 = Select[data, 10 <= First[#] <= 65 &];

ts2 = TimeSeries[dat2] ~TimeSeriesRescale~ {60, 140};

dat3 = {#, #2 - ts2[#]} & @@@ dat1;

ListPlot[{dat1, dat2, dat3}]

enter image description here

See also TimeSeriesResample.


Addendum

If I follow what you're asking for in the comments, try this:

ts2raw = TimeSeries[dat2];

datX = Array[{#, ts2raw@#} &, Length @ dat1, MinMax[First /@ dat2]];

Closely related but allowing for nonuniform sampling:

{t1, t2} = {dat1, dat2}[[All, All, 1]];
{m1, m2} = MinMax /@ {t1, t2};
ts2 = TimeSeries[dat2];

datY = {#, ts2@#} & /@ Rescale[t1, m1, m2];

Or:

{ts1, ts2} = TimeSeries /@ {dat1, dat2};
times = TimeSeriesRescale[ts1, MinMax @ ts2["Times"]]["Times"];

tsX = TimeSeriesResample[ts2, {times}]

TimeSeries provides a fairly direct approach to this:

data = Import["https://pastebin.com/raw/QCAKwZ2P", "Package"];

dat1 = Select[data, 60 <= First[#] <= 140 &];
dat2 = Select[data, 10 <= First[#] <= 65 &];

ts2 = TimeSeries[dat2] ~TimeSeriesRescale~ {60, 140};

dat3 = {#, #2 - ts2[#]} & @@@ dat1;

ListPlot[{dat1, dat2, dat3}]

enter image description here

See also TimeSeriesResample.


Addendum

If I follow what you're asking for in the comments, try this:

ts2raw = TimeSeries[dat2];

datX = Array[{#, ts2raw@#} &, Length @ dat1, MinMax[First /@ dat2]];

TimeSeries provides a fairly direct approach to this:

data = Import["https://pastebin.com/raw/QCAKwZ2P", "Package"];

dat1 = Select[data, 60 <= First[#] <= 140 &];
dat2 = Select[data, 10 <= First[#] <= 65 &];

ts2 = TimeSeries[dat2] ~TimeSeriesRescale~ {60, 140};

dat3 = {#, #2 - ts2[#]} & @@@ dat1;

ListPlot[{dat1, dat2, dat3}]

enter image description here

See also TimeSeriesResample.


Addendum

If I follow what you're asking for in the comments, try this:

ts2raw = TimeSeries[dat2];

datX = Array[{#, ts2raw@#} &, Length @ dat1, MinMax[First /@ dat2]];

Closely related but allowing for nonuniform sampling:

{t1, t2} = {dat1, dat2}[[All, All, 1]];
{m1, m2} = MinMax /@ {t1, t2};
ts2 = TimeSeries[dat2];

datY = {#, ts2@#} & /@ Rescale[t1, m1, m2];

Or:

{ts1, ts2} = TimeSeries /@ {dat1, dat2};
times = TimeSeriesRescale[ts1, MinMax @ ts2["Times"]]["Times"];

tsX = TimeSeriesResample[ts2, {times}]
added 191 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

TimeSeries provides a fairly direct approach to this:

data = Import["https://pastebin.com/raw/QCAKwZ2P", "Package"];

dat1 = Select[data, 60 <= First[#] <= 140 &];
dat2 = Select[data, 10 <= First[#] <= 65 &];

ts2 = TimeSeries[dat2] ~TimeSeriesRescale~ {60, 140};

dat3 = {#, #2 - ts2[#]} & @@@ dat1;

ListPlot[{dat1, dat2, dat3}]

enter image description here

See also TimeSeriesResample.


Addendum

If I follow what you're asking for in the comments, try this:

ts2raw = TimeSeries[dat2];

datX = Array[{#, ts2raw@#} &, Length @ dat1, MinMax[First /@ dat2]];

TimeSeries provides a fairly direct approach to this:

data = Import["https://pastebin.com/raw/QCAKwZ2P", "Package"];

dat1 = Select[data, 60 <= First[#] <= 140 &];
dat2 = Select[data, 10 <= First[#] <= 65 &];

ts2 = TimeSeries[dat2] ~TimeSeriesRescale~ {60, 140};

dat3 = {#, #2 - ts2[#]} & @@@ dat1;

ListPlot[{dat1, dat2, dat3}]

enter image description here

See also TimeSeriesResample.

TimeSeries provides a fairly direct approach to this:

data = Import["https://pastebin.com/raw/QCAKwZ2P", "Package"];

dat1 = Select[data, 60 <= First[#] <= 140 &];
dat2 = Select[data, 10 <= First[#] <= 65 &];

ts2 = TimeSeries[dat2] ~TimeSeriesRescale~ {60, 140};

dat3 = {#, #2 - ts2[#]} & @@@ dat1;

ListPlot[{dat1, dat2, dat3}]

enter image description here

See also TimeSeriesResample.


Addendum

If I follow what you're asking for in the comments, try this:

ts2raw = TimeSeries[dat2];

datX = Array[{#, ts2raw@#} &, Length @ dat1, MinMax[First /@ dat2]];
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

TimeSeries provides a fairly direct approach to this:

data = Import["https://pastebin.com/raw/QCAKwZ2P", "Package"];

dat1 = Select[data, 60 <= First[#] <= 140 &];
dat2 = Select[data, 10 <= First[#] <= 65 &];

ts2 = TimeSeries[dat2] ~TimeSeriesRescale~ {60, 140};

dat3 = {#, #2 - ts2[#]} & @@@ dat1;

ListPlot[{dat1, dat2, dat3}]

enter image description here

See also TimeSeriesResample.