Finding weighted sum of multiple curves

5 Ansichten (letzte 30 Tage)
Deepa Maheshvare
Deepa Maheshvare am 5 Jul. 2022
Bearbeitet: Adam Danz am 7 Jul. 2022
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 Kommentare
Adam Danz
Adam Danz am 6 Jul. 2022
I still don't have a mental image of what the results should look like. Could you illustrate that?
Deepa Maheshvare
Deepa Maheshvare am 7 Jul. 2022
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Adam Danz
Adam Danz am 7 Jul. 2022
Bearbeitet: Adam Danz am 7 Jul. 2022
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)

Weitere Antworten (0)

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by