I have found information about similar topics, but wasn´t useful for me.
I have the next 2 signals registered by a laser profilometer.

As can be seen in the picture the signals are almost equals but are not in phase. What i need is to displace the red signal over the blue one finding the more likely point of union to get a third signal.
I have tried with this code, but it does not work, i obtain zero in the lag, i suspect that it is caused becouse the signals length is the same. I am programming in MATLAB
[acor,lag] = xcorr(p2,p1);
[~,I] = max(abs(acor));
lagDiff = lag(I);
The two signals are attached.
Regards!