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
0 件のコメント
採用された回答
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
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!