Minimize distance between curves
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1052865/image.png)
Suggestions will be really appreciated.
3 comentarios
John D'Errico
el 4 de Jul. de 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.
Respuestas (1)
John D'Errico
el 1 de Jul. de 2022
Editada: John D'Errico
el 1 de Jul. de 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.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!