在Malab仿真中创建两行图例

时间:2017-09-11 01:30:31

标签: matlab matlab-figure legend matlab-guide

我想在Matlab中创建2行图例。我想绘制2行,每行有8行,从e(11,k)到e(44,k)  经过一番阅读,我仍然坚持这个,你能帮我解决问题吗?

这是我的代码,用于制作包含16行图例

的1行
t_end=30;T=1;
% initialization
e(11,1:t_end)=0;e(21,1:t_end)=0;e(31,1:t_end)=0;e(41,1:t_end)=0;
e(12,1:t_end)=0;e(22,1:t_end)=0;e(32,1:t_end)=0;e(42,1:t_end)=0;
e(13,1:t_end)=0;e(23,1:t_end)=0;e(33,1:t_end)=0;e(43,1:t_end)=0;
e(14,1:t_end)=0;e(24,1:t_end)=0;e(34,1:t_end)=0;e(44,1:t_end)=0;

for k=1:t_end-1
    e(11,k)=sin(10*k)+1;
    e(21,k)=sin(20*k)+1;e(31,k)=sin(30*k)+1;e(41,k)=sin(40*k)+1;
    e(12,k)=sin(50*k)+2;
    e(22,k)=sin(60*k)+1;e(32,k)=sin(70*k)+2;e(42,k)=sin(80*k)+2;
    e(13,k)=sin(90*k)+3;
    e(23,k)=sin(100*k)+3;e(33,k)=sin(110*k)+3;e(43,k)=sin(120*k)+3;
    e(14,k)=sin(130*k)+4;
    e(24,k)=sin(140*k)+4;e(34,k)=sin(150*k)+4;e(44,k)=sin(160*k)+4;
end

figure
hold on
k11 = plot(T*[0:t_end-2], e(11,1:t_end-1), '-b');
k21 = plot(T*[0:t_end-2], e(21,1:t_end-1), '-b');
k31 = plot(T*[0:t_end-2], e(31,1:t_end-1), '-b');
k41 = plot(T*[0:t_end-2], e(41,1:t_end-1), '-b');

k12 = plot(T*[0:t_end-2], e(12,1:t_end-1), '-k');
k22 = plot(T*[0:t_end-2], e(22,1:t_end-1), '-k');
k32 = plot(T*[0:t_end-2], e(32,1:t_end-1), '-k');
k42 = plot(T*[0:t_end-2], e(42,1:t_end-1), '-k');

k13 = plot(T*[0:t_end-2], e(13,1:t_end-1), '-m');
k23 = plot(T*[0:t_end-2], e(23,1:t_end-1), '-m');
k33 = plot(T*[0:t_end-2], e(33,1:t_end-1), '-m');
k43 = plot(T*[0:t_end-2], e(43,1:t_end-1), '-m');


k14 = plot(T*[0:t_end-2], e(14,1:t_end-1), '-g');
k24 = plot(T*[0:t_end-2], e(24,1:t_end-1), '-g');
k34 = plot(T*[0:t_end-2], e(34,1:t_end-1), '-g');
k44 = plot(T*[0:t_end-2], e(44,1:t_end-1), '-g');

h = legend([k11 k21 k31 k41 k12 k22 k32 k42 k13 k23 k33 k43 k14 k24 k34 k44],'$e_{11}$','$e_{21}$','$e_{31}$','$e_{41}$','$e_{12}$','$e_{22}$','$e_{32}$','$e_{42}$','$e_{13}$','$e_{23}$','$e_{33}$','$e_{43}$','$e_{14}$','$e_{24}$','$e_{34}$','$e_{44}$');
set(h,'Interpreter','latex');
h.Orientation = 'horizontal';

0 个答案:

没有答案