# Shifting one curve to a reference curve using error minimization (fmincon from the Minimization Toolbox)

3 views (last 30 days)
Saeid on 5 Nov 2021
Answered: Saeid on 22 Nov 2021
I need to shift the red curve ONLY horizontally to overlap with the black one. This should be possible using error minimization (e.g. fmincon in the Optimization Toolbox) but I have not managed to do this so far. How can I do this?
##### 2 CommentsShowHide 1 older comment
Saeid on 5 Nov 2021
The Data are in the excel attachment. [x1 y1] are the reference (black) and [x2 y2] are the data to be shifted horizontally. I want the shifting to be automatic, because in real life there is a large number of such datasets.

Mathieu NOE on 5 Nov 2021
hello again
as we look at data plotted in log log scale, a x shift is in fact a multiplicative coefficient on the Y amplitude
see the code and results below
I removed in my computation the first X samples where the two curve are not really parallel so it matches better for x > 10
clc
clearvars
X1 = data.x1;
Y1 = data.y1;
X2 = data.x2;
Y2 = data.y2;
% avoid taking into account first samples where two curves are not parallel
a = (Y1./Y2);
b = abs(a./rms(a));
ind = find( b> 0.5 & b < 2 );
am = rms(a(ind));
loglog(X1,Y1,X2,Y2,X2,Y2.*am);
legend('curve 1','curve 2' ,'curve 2 shifted');
Mathieu NOE on 19 Nov 2021
hello
problem solved ?

Saeid on 21 Nov 2021
Hi Mathieu,
thanks for the elaborate response and sorry for my late reply. Yes, it worked pretty well!
Saeid
Mathieu NOE on 22 Nov 2021
hello Saeid
would you mind accepting my answer ?
tx !

Saeid on 22 Nov 2021
Sure. I just did!

R2021b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by