2
$\begingroup$

I have a data set "data9k" with x varying from 0 to 365, and another data "data0" set with x varying from 0 to 365. But the x values for both data sets are not same but similar. I want to subtract the y values of "data0" from "data9k". I am assuming I should first interpolate both data9k and data0 from 0 to 360 [I only want the 0 to 360 range] and then subtract them? How should I interpolate? Is there a better way to do this?

Here are my data sets

data9k = {{1.1172, 4.62*10^-8}, {12.619, 4.47*10^-8}, {24.638, 
  4.44*10^-8}, {35.7164, 4.34*10^-8}, {47.7885, 4.14*10^-8}, {59.3201,
   4.14*10^-8}, {71.6327, 3.83*10^-8}, {83.2878, 
  3.44*10^-8}, {94.4534, 3.39*10^-8}, {106.053, 3.06*10^-8}, {118.451,
   3.16*10^-8}, {130.402, 3.32*10^-8}, {142.897, 
  3.59*10^-8}, {155.719, 4.02*10^-8}, {167.718, 4.35*10^-8}, {179.867,
   4.85*10^-8}, {191.746, 4.8*10^-8}, {203.29, 4.99*10^-8}, {215.511, 
  5.43*10^-8}, {227.228, 5.56*10^-8}, {238.653, 6.02*10^-8}, {251.438,
   5.83*10^-8}, {263.693, 5.85*10^-8}, {275.223, 
  5.27*10^-8}, {287.595, 5.01*10^-8}, {299.263, 5.01*10^-8}, {310.811,
   4.85*10^-8}, {322.76, 4.94*10^-8}, {334.224, 4.99*10^-8}, {346.385,
   4.84*10^-8}, {358.353, 4.84*10^-8}, {365.005, 
  4.39*10^-8}, {365.005, 4.68*10^-8}};
data0 = {{1.72155, 6.26*10^-8}, {13.866, 6.02*10^-8}, {25.3934, 
  5.76*10^-8}, {36.5356, 5.38*10^-8}, {48.7993, 5.24*10^-8}, {60.9991,
   5.12*10^-8}, {72.9415, 5.*10^-8}, {84.1156, 4.91*10^-8}, {95.8728, 
  5.01*10^-8}, {108.136, 5.08*10^-8}, {119.668, 5.06*10^-8}, {131.259,
   5.25*10^-8}, {142.742, 5.31*10^-8}, {154.806, 
  5.62*10^-8}, {166.376, 5.82*10^-8}, {177.496, 5.89*10^-8}, {189.637,
   6.1*10^-8}, {202.158, 6.35*10^-8}, {214.349, 6.57*10^-8}, {226.658,
   6.74*10^-8}, {238.496, 6.77*10^-8}, {250.744, 
  6.87*10^-8}, {262.746, 6.91*10^-8}, {274.316, 6.94*10^-8}, {286.446,
   6.92*10^-8}, {298.52, 6.95*10^-8}, {310.33, 6.76*10^-8}, {322.292, 
  6.57*10^-8}, {334.268, 6.45*10^-8}, {345.836, 6.16*10^-8}, {357.444,
   5.97*10^-8}, {364.946, 5.85*10^-8}, {365.005, 5.92*10^-8}};
$\endgroup$
3
$\begingroup$
if0 = Interpolation[data0, 
   "ExtrapolationHandler" -> {Automatic, "WarningMessage" -> False}];

difference = {#, #2 - if0 @ #} & @@@ data9k;

ListLinePlot[{data0, data9k, difference}, ImageSize -> Large, 
 PlotLegends -> {"data0", "data9k", "difference"}]

enter image description here

An alternative approach is to use TemporalData:

td0 = TemporalData[#2, {#}, ResamplingMethod -> {"Interpolation", 
       InterpolationOrder -> 1}] & @@ Transpose @ data0;

difference2 = Quiet @ {#, #2 - td0["PathFunction"] @ #} & @@@ data9k;

ListLinePlot[{data0, data9k, difference2}, ImageSize -> Large, 
 PlotLegends -> {"data0", "data9k", "difference"}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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