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 view (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Star Strider
on 4 Jul 2019
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.
2 Comments
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!