Matlab如何使用代码添加图例(legend)

2024-10-21 20:48:06

1、如图所示,首先打开matlab软件。

Matlab如何使用代码添加图例(legend)

2、如图所示,点击红框勾选按钮,新建一个文件。

Matlab如何使用代码添加图例(legend)

3、输入以下代码。x = 0:pi/50:2*pi;y = sin(x);y1=cos(x);figur髫潋啜缅e plot(x,y,'r')hold onplot(x,y1,'b')

Matlab如何使用代码添加图例(legend)

4、得到如图所示的图形,可以看到这个图形没有图例。

Matlab如何使用代码添加图例(legend)

5、如图所示,在上述代码中加入一行代码:legend('a','b');

Matlab如何使用代码添加图例(legend)

6、如图所示,图形中加入了图例。

Matlab如何使用代码添加图例(legend)
猜你喜欢