필터 지우기
필터 지우기

How to deal with legend for multiple curves in one figure?

조회 수: 23 (최근 30일)
Haitham AL Satai
Haitham AL Satai 2022년 7월 20일
댓글: Voss 2022년 7월 20일
I have a multiple curevs in one figure and I wanna add a legend to each curve.
So, instead of data1, data2, data3, data4, and data5, I want to replace them with
phi = 0 & psi = 0
phi = psi
phi = [0,5,10,15,20,25,30] & psi = 0
phi = 0 & psi = [0,5,10,15,20,25,30]
phi = [0,5,10,15,20,25,30] & psi = [0,5,10,15,20,25,30]
I tried many times, but I could not reach to solution. May I get an assistance please?

채택된 답변

Voss
Voss 2022년 7월 20일
편집: Voss 2022년 7월 20일
One way is to set the DisplayName of each line when you plot it:
names = {
'phi = 0 & psi = 0'
'phi = psi'
'phi = [0,5,10,15,20,25,30] & psi = 0'
'phi = 0 & psi = [0,5,10,15,20,25,30]'
'phi = [0,5,10,15,20,25,30] & psi = [0,5,10,15,20,25,30]'
};
hold on % do "hold on" before you plot
for ii = 1:5
plot(rand(1,10),rand(1,10),'DisplayName',names{ii}); % (plotting random data because I don't have your data)
end
xlabel('X (m)');
ylabel('Received power (dBm)');
legend();
  댓글 수: 4
Haitham AL Satai
Haitham AL Satai 2022년 7월 20일
@Voss I accepted your answer sir. Thanks a lot.
Voss
Voss 2022년 7월 20일
Thank you!

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

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