Minimize distance between curves
Show older comments
I have a dataset with values of multiple curves. An example plot is shown below.
I want to shift the curves (up/down) so that all curves overlap. This would mean the data points in each curve is scaled up/down by a factor.
I am not sure how to frame this as a mathematical problem (to minimize the vertical distance between each pair of curves) and determine the scaling factor
for each curve. I tried to start by computing the pair-wise distance matrix using norm fucntion
but I am not sure what to do next and which MATLAB function can be used for set up this problem.

Suggestions will be really appreciated.
3 Comments
John D'Errico
on 4 Jul 2022
Please don't answer your question with an answer just to provide feedback on an answer.
I am really sorry for the late reponse. Thank you so much for the answer.
I would like to share a sample of my real dataset that looks like the below. The curves don't have a common x, so I am not sure
how to deifine the target curve.
ThemeCopy
scale = 1.5;
x1 = [0,4,6,10,15,20]*scale;
y1 = [18,17.5,13,12,8,10];
x2 = [0,10.5,28]*scale;
y2= [18.2,10.6,10.3];
x3 = [0,4,6,10,15,20]*scale;
y3 = [18,13,15,12,11,9.6];
x4 = [9,17,28]*scale;
y4 = [5,5.5,7];
x5 = [1,10,20]*scale;
y5 = [3,0.8,2];
plot(x1,y1, '*-', x2, y2, '*-', x3, y3, '*-', x4, y4, '*-', x5, y5, '*-')
"In the event that you also needed a constant additive translation up or down"
Could you please explain this a bit?
John D'Errico
on 4 Jul 2022
I note that the PICTURE you originally showed had all curves with the same x values. But then when you provide data, nothing of the sort happens.
SIgh.
Deepa Maheshvare
on 5 Jul 2022
Answers (1)
John D'Errico
on 1 Jul 2022
Edited: John D'Errico
on 1 Jul 2022
This is a classic calibration problem of sorts. Lacking any data, I cannot really help you as much as I might want to. But I can at least generate some fake data. If you want to provide some data, feel free to do so, attached to a comment.
First, you need to decide if the problem is PURELY that of a scaling problem, or if you wanted to add some constant also to each curve to translate it up and down.
Next, you will need to choose some target curve. Which one will be the aim, the one that all others will be adjusted to look like?
For example, here is some fake data I just made up:
x = 0:10; nx = length(x);
ytar = 2*x - x.^2/10 + randn(size(x))/8;
plot(x,ytar,'-o')
So a little noise in it. But not too bad.
Now I'll generate some other random curves that we will need to adjust. 5 curves should be about right.
ny = 5;
ydata = (randn(ny,1)+2)*ytar + randn(ny,nx)/2;
plot(x',ydata','r-',x,ytar,'b-o')
Does that seem at least similar to what you have?
Now, each of those curves need to be adjusted by a pure scale factor to look like the ytar curve. We can do that using some simple linear algebra. Backslash is your friend here.
calconstants = ytar'\ydata'
These are the scale factors we need to re-scale the data, to make all of the curves look like the ytar curve. Il plot them all on top of each other now, after re-scaling.
ycal = ydata./calconstants'
plot(x',ycal','r-',x,ytar,'b-o')
As you can see, all of the red curves now look as much as possible like the blue curve.
In the event that you also needed a constant additive translation up or down, that is also possible, but I don't have your data to know if that would be useful.
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

