Finding weighted sum of multiple curves
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam Danz
2022-7-6
I still don't have a mental image of what the results should look like. Could you illustrate that?
采纳的回答
Adam Danz
2022-7-7
编辑:Adam Danz
2022-7-7
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)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!