Matlab:情节中的变量图例

时间:2014-06-05 16:04:20

标签: matlab legend

我有一个图,其中我绘制了可变数量的点(类似于网络的节点)和三个轨迹。当我拨打legend时,我也会获得o符号(对应于节点)的轨迹。

我知道这是因为legend函数需要一个字符串用于我需要的每个标签,但是因为我不能知道节点的总数"先验" (因为它是用户定义的参数),是否有一种方法可以指定只有节点标记为o,同时能够正常标记轨迹?

1 个答案:

答案 0 :(得分:1)

您只需告诉legend您想要的确切内容。

轨迹:

t(1) = plot( xvector1, yvector1, linspecs ...)
t(2) = plot( xvector2, yvector2, ...)
...
t(n) = plot( xvectorn, yvectorn, ...)

及其标签:

tLabel{1} = 'trajectory label #1'
...
tLabel{n} = 'trajectory label #n'

节点相同:

p(1) = plot( x1, y1, 'o',...)
p(2) = plot( x2, y2, 'o',...)
...
p(m) = plot( xm, ym, 'o',...)

pLabel{1} = 'node label #1'
...
pLabel{m} = 'node label #m'

最终绘制了传奇:

lh = legend( [traj(1:n),p(1:m)] , tLabel{1:n}, pLabel{1:m} );

当然,如果所有节点都具有相同的名称和样式,只需使用节点数组的第一个条目:

lh = legend( [traj(1:n),p(1)] , tLabel{1:n}, pLabel{1} );
相关问题