breaking legend into 2 columns

Hi to everyone. I use a MATLAB code to draw a graph. the legends are too big and cover a part of the graph. I wanted to make it in 2 columns. i saw some solutions on the net which explain how to change the functions to make the legend in multiple columns. However, my program reads the data from an excel file and their solutions don't work for me. Could anybody please help me to solve this issue? Sorry if my question is naive, I'm not good in MATLAB. I also birng my code here:
A=xlsread('C:\temp.xlsx','A1:A10');
B=xlsread('C:\temp.xlsx','B1:B10');
C=xlsread('C:\temp.xlsx','C1:C10');
D=xlsread('C:\temp.xlsx','D1:D10');
E=xlsread('C:\temp.xlsx','E1:E10');
F=xlsread('C:\temp.xlsx','F1:F10');
G=xlsread('C:\temp.xlsx','G1:G10');
plot(A,B,A,C,A,D,A,E,A,F,A,G)
hold on;
axis([10 100 -10 0])
xlabel('length')
ylabel('BER')
legend('AAAAAAAAAA','BBBBBBBBBB','CCCCCCCCCC','DDDDDDDDDD','EEEEEEEEEEE','FFFFFFFFFF')

2 件のコメント

Purushottama Rao
Purushottama Rao 2015 年 6 月 22 日
did not it work?
legend( sprintf( '%s\n%s', 'line1', 'line2' ) )
MAJID MM
MAJID MM 2015 年 6 月 22 日
編集済み: MAJID MM 2015 年 6 月 22 日
Thanks for your response, but could you please tell me how can I rewrite my legend command using your legend command? I have 6 parameters and want to make it into 2* 3 parameters.

サインインしてコメントする。

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 6 月 22 日

0 投票

You can specify the location outside
A=0:0.1:10
B=sin(A)
C=cos(A)
D=B.^2
E=C.^2
F=A.^2/100
G=-F
plot(A,B,A,C,A,D,A,E,A,F,A,G)
%hold on;
%axis([10 100 -10 0])
xlabel('length')
ylabel('BER')
leg={'AAAAAAAAAA','BBBBBBBBBB','CCCCCCCCCC','DDDDDDDDDD','EEEEEEEEEEE','FFFFFFFFFF'}
legend(leg,'Location','EastOutside')

3 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 6 月 22 日
MAJID MM
MAJID MM 2015 年 6 月 22 日
Thanks Azzi, but an error appears, that "leg" is unidentified variable or class. BTW what would be the output? the location doesn't matter. because I can move the legend inside the graph. I just want to make it into 2 column to can fit it in empty space
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 6 月 22 日
編集済み: Azzi Abdelmalek 2015 年 6 月 22 日
Like I said, look at File Exchange contributions, copy <http://www.mathworks.com/matlabcentral/fileexchange/27389-columnlegend/content//columnlegend/columnlegend.m this function> and use it.
leg={'AAAAAAAA','BBBBBBBB','CCCCCCCC','DDDDDDDD','EEEEEEEEE','FFFFFFFF'}
[legend_h,object_h,plot_h,text_strings] = columnlegend(2, leg)

サインインしてコメントする。

カテゴリ

タグ

質問済み:

2015 年 6 月 22 日

編集済み:

2015 年 6 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by