Finding weighted sum of multiple curves

I have a dataset with values of multiple curves. An example plot is shown below.
I want to scale the curves (move up/down) so that all curves overlap.
The following is a sample dataset which includes that data points corresponding to 5 curves and coordinate inputs below
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, '*-')
To scale the curves, I need to find the scale factor by defining a target curve.
I'm not sure of the ways in which the target curve can be defined. Would it be a good
approach to compute the weighted sum? Since the x scale is different for each curve, I am not sure
how to define an average/ target curve.
Suggestions will be really appreciated.

6 Comments

This sounds like an XY Problem.
I think this is the real goal:
> I want to scale the curves (move up/down) so that all curves overlap.
but you're asking about,
> Finding weighted sum of multiple curves
If this is correct, please elaborate on the goal. What kind of transformations do you expect? For example, do you expect the curves to merely shift vertically with no other changes? Should the curves minimum be at y=0?
Thank you for the reply. I'm sorry if I wasn't clear. Yes, I want to merely shift the curves vertically to bring all the curves closer. But I don't want to move all the curves with respect to 1 curve (this will bias the solution). So I am trying to define the traget curve by finding the weighted sum. I don't want the curve minimum to be at y<=0.
What defines the weights?
What are you summing?
I was thinking the function values have to be summed. But not sure how the weigths have to be chosen.
If there are oher suggestions, I would be happy to know
I still don't have a mental image of what the results should look like. Could you illustrate that?
I a sorry, I don't have a clear idea of how the curve should like. But I am looking for a mean curve like the below

Sign in to comment.

 Accepted Answer

The first step of applying a weighted sum is to define the weights so until you know that, you can't use that method.
Instead, another option is to interpolate each curve so that the curves have the same x-coordinates within the range of each curve. Then you can just average the y values.
Data from OP question
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 initial data
fig = figure;
ax = cla(fig);
plot(ax, x1,y1, '*-', x2, y2, '*-', x3, y3, '*-', x4, y4, '*-', x5, y5, '*-', 'markersize', 12)
grid(ax,'on')
Interpolate x and y
xi are the interpolated x values, all curves will have the same xi. You can define xi differently but it should span the range of your data which is currently 0 to 42.
yi are the interpolated y values. NaNs are mising values for curves that do not span the entire xi range.
xi = 0 : 1 : 42; % your choice but should span the range of your data
y1i = interp1(x1,y1,xi);
y2i = interp1(x2,y2,xi);
y3i = interp1(x3,y3,xi);
y4i = interp1(x4,y4,xi);
y5i = interp1(x5,y5,xi);
Plot the interpolated values
This step isn't necessary but it's always good to get visual feedback that the process makes sense. Here, vertical "pipes" are placed at the interpolated points. Compare them to the original points with "*".
hold(ax, 'on')
ax.ColorOrderIndex = 1; % reset color order to use the same colors as above
plot(ax, xi,y1i, '|-', xi, y2i, '|-', xi, y3i, '|-', xi, y4i, '|-', xi, y5i, '|-', 'markersize',4)
Average the interpolated y coordinates
yAvg = mean([y1i;y2i;y3i;y4i;y5i],'omitnan');
Add the average line to the plot
plot(xi, yAvg, 'r--','LineWidth',2)

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Products

Release

R2021a

Community Treasure Hunt

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

Start Hunting!