0

谁能告诉我为什么我legend给我错误信息:

b=data(:,1);    
hold on
plot(b,a,'r');
plot(b,a1,'b');
hold off
legend('L','S'); 

代码在没有 的情况下运行良好legend,但看不到图中的图例。

编辑
这是我收到的错误消息:

Attempted to access legend(76,83);
index out of bounds because size(legend)=[1,10]
4

2 回答 2

2

您的工作区中有一个名为的变量legend。MATLAB 解释legend('L','S')为对变量 'L' (76) 和 'S' (83) 的字符值的索引调用legend

将图例重命名为其他名称,并确保在再次运行代码之前清除它。

将来,如果您不确定您正在使用的变量名称是否是预先存在的 MATLAB 函数,您可以随时help functionName在工作区中键入。

于 2013-06-12T19:45:16.080 回答
0

尝试 :

b=data(:,1);
plot(b,a,'r');
hold on
plot(b,a1,'b');
legend('L','S'); 
hold off
于 2013-06-12T19:43:16.280 回答