Effacer les filtres
Effacer les filtres

How do you plot the average of a group of lines in a figure?

1 vue (au cours des 30 derniers jours)
Jacob Capito
Jacob Capito le 10 Mai 2022
Réponse apportée : Chunru le 11 Mai 2022
I have a group of lines that represent the damping of a system for a given mode and I want to find the average trendline just from using the data given to me in the graph. I don't have the x and y datapoints and it would be a pain to try to go get them. Is there a way to make an average trendline just from the lines given to me in the figure?
The only things I have available to me are a vector of object type "line" from the figure and the figure itself
  3 commentaires
Jacob Capito
Jacob Capito le 10 Mai 2022
Yeah I just added my fig file to my post.
Image Analyst
Image Analyst le 10 Mai 2022
I'd rather have the original data, not a .fig file visualization of it. Can you attach the original data in a .mat file or text file? Then I'd just interpolate all the curves on a common x-axis, add up all the values and divide by the number of curves.

Connectez-vous pour commenter.

Réponse acceptée

Chunru
Chunru le 11 Mai 2022
h = openfig("Damping_mode_2.fig", "visible");
hl = findobj(h, 'Type', 'Legend');
hl.Location = 'southoutside'; hl.NumColumns = 4; hl.FontSize = 5;
hlines = findobj(gca, 'Type', 'Line');
for i=1:length(hlines)
x{i,1} = hlines(i).XData;
%size(x{i})
y{i,1} = hlines(i).YData;
name{i,1} = hlines(i).DisplayName;
end
% convert to matrix
x = cell2mat(x)';
y = cell2mat(y)';
xmin = min(x(:)); xmax=max(x(:));
xg = linspace(xmin, xmax, 51);
yg = zeros(length(xg), size(x,2));
% interpolate the data
for i=1:size(x, 2)
yg(:, i) = interp1(x(:,i), y(:,i), xg, 'linear', 'extrap');
end
ymean = mean(yg, 2);
hold on
plot(xg, ymean, 'r', 'LineWidth', 4, 'DisplayName', 'mean');

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by