I have attached a fig file in which I have used 3 legends for upper, middle and lower curve, respectively. Actually, there are six lines in each curve but I want each curve to look like a single line. How is it possible using fig file.

1 次查看(过去 30 天)
I have attached a fig file in which I have used 3 legends for upper, middle and lower curve, respectively. Actually, there are six lines in each curve but I want each curve to look like a single line. How is it possible using fig file.

采纳的回答

Star Strider
Star Strider 2019-7-4
Try this:
I = openfig('comp25.fig');
Ax = gca;
lgnd = Ax.Legend;
Lines = findobj(Ax,'Type','line');
for k1 = 1:fix(numel(Lines)/6) % Consider 6 ‘Lines’ In Each Iteration
for k2 = 1:6
X(k2,:) = Lines(k2+(k1-1)*6).XData; % Get ‘X’ Values For This Set
Y(k2,:) = Lines(k2+(k1-1)*6).YData; % Get ‘Y’ Values For This Set
end
Xm(k1,:) = X(1,:); % X-Vector (For Plot)
Ym(k1,:) = mean(Y); % Y-Vector (For Plot) - Uses ‘mean’, ‘median’ Or Others May Be Appropriate As Well
end
figure
semilogy(Xm', Ym')
grid
legend(Ax.Legend.String)
xlabel(Ax.XLabel.String)
ylabel(Ax.YLabel.String)
It is difficult to determine what you want for each single line, so here I took th mean of each consecutive group of 6 Line objects.

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by