How can I find the average of several lines whose datasets are different lengths?

59 次查看(过去 30 天)
I'm able to plot the various datasets altogether thanks to normalizing the x axis values, but I need to find the 'average line' per say.
I'm unable to use a mean function because the datasets are differing lengths, any ideas?
for i = 1:length(plot_limit)
frame = find((inverse_kin(:,1) >= plot_limit(i,1)) & (inverse_kin(:,1) <= plot_limit(i,2)));
x{i} = normalize(inverse_kin(frame,1),'range',[0 100]);
y{i} = inverse_kin(frame,9);
end
figure;
hold on
for i = 1:length(plot_limit)
graph(i) = plot(x{i},y{i});
end
hold off

采纳的回答

Image Analyst
Image Analyst 2021-9-16
编辑:Image Analyst 2021-9-16
I suggest you resample each curve with interp1() so that all your curves are using a common set of x values. Then simply add them up and divide by the number. Something like (untested):
numPoints = 1000; % Whatever resolution you want.
xCommon = linspace(0, 100, numPoints);
ySum = zeros(1, numPoints);
for k = 1 : numberOfCurves
% Somehow get this particular set of x and y
thisx =
thisy =
% Interpolate y so that it's using a common x axis.
yCommon = interp1(thisx, thisy, xCommon);
% Add it in to the other curves.
ySum = ySum + yCommon;
end
% Divide the sum by the number of curves to get the average curve.
yAverage = ySum / numberOfCurves;

更多回答(1 个)

the cyclist
the cyclist 2021-9-16
One possible solution would be to interpolate (e.g. with spline function) using the interp1 function, to a common grid of points along the x-axis, then take the mean over those points.

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by