I have a list of the form data={{t1,x1}, {t2,x2},...} and a list newt = {nt1,nt2,...} and I want to expand data to these new times to become {{nt1,x(1)},{nt2,x(2)},{nt3,x(3)},...} where x(i) is equal to the xi of whichever data point is preceding nti.
I assume that t1<=t2<=t3<=.., nt1<=nt2<=... and the old times is a subset of the new ones.
I did this the following way, but it is far too slow:
PadDataList[l_, grid_] := Module[ {lind = 1, len = Length@l}, MapIndexed[( If[# > l[[lind, 1]] && lind < len, lind++]; {#, l[[lind, 2]]} ) &, grid ]]; data = Sort[RandomReal[1, {50000, 2}], First@#1 < First@#2 &]; newgrid = Union@Join[data[[All, 1]], RandomReal[1, {50000}]]; AbsoluteTiming[PadDataList[data, newgrid];] (* 0.4 seconds *) Is there a cleverer and more efficient way to do this?
I am using this together with another function that takes multiple lists like above and creates a new list with elements f[nti,x(i),y(i),...]
Excuse the abuse of (i) syntax
Interpolation. It has an option calledInterpolationOrderwhich you could set to zero. $\endgroup$