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

4 Ansichten (letzte 30 Tage)
Jacob Capito
Jacob Capito am 10 Mai 2022
Beantwortet: Chunru am 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 Kommentare
Jacob Capito
Jacob Capito am 10 Mai 2022
Yeah I just added my fig file to my post.
Image Analyst
Image Analyst am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Chunru
Chunru am 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');

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots 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