Could anyone help me to solve the issue

조회 수: 1 (최근 30일)
Prabha Kumaresan
Prabha Kumaresan 2018년 3월 7일
댓글: Rik 2018년 3월 9일
I want to compare the performance of two systems lets say A and B. I am getting the graph as i have attached it. for legend i have used the command
legend('A','B')
from the graph it is well clear B have better performance than A. so how to have the legend such that B comes first followed by A.

채택된 답변

Rik
Rik 2018년 3월 7일
편집: Rik 2018년 3월 7일
You need to save the handles to the line objects (i.e. the output of plot) in an array. Then you can re-order that array as you please. If you use the 'DisplayName' option in plot, you can avoid having to re-order a cell with the names as well.
%example:
h=[];%make sure h is empty
h(1)=plot(1:5,5+rand(1,5),'rd-','DisplayName','A');
hold on
h(2)=plot(1:5,7+rand(1,5),'bd-','DisplayName','B');
%re-order
order=[2 1];
h=h(order);
legend(h)
Another method is just to re-order the legend once you have it:
h = gca;
hC = findobj(h,'Type','line');
order=[2 1];
legend(hC(order));
  댓글 수: 1
Rik
Rik 2018년 3월 9일
If you found this answer useful, please mark it as accepted answer. It will give me reputation points and will make it easier for other people with the same question to find an answer.

댓글을 달려면 로그인하십시오.

추가 답변 (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