MATLAB: How to compare two 2D curves which have shifted x value

comparevectors

I have two 2D curves, X1,Y1,X2,Y2 are 1D vectors. (X1, Y1) and (X2, Y2), I would like find difference of Y2 and Y1, but the X1 value is not exactly the same. They are shifted by half bin size. Is there easy way i can compare Y at same X value? Thanks!

Best Answer

I would use the interp1 function.
Example:
Y2i = interp1(X1, Y1, X2, 'linear', 'extrap');
or:
Y1i = interp1(X2, Y2, X1, 'linear', 'extrap');
depending on what you want to do.
Related Question