admin 管理员组

文章数量: 1086019


2024年2月26日发(作者:nl型泥浆泵)

matlab 中plot函数的用法

在 MATLAB 中,plot 函数用于绘制二维图形,包括线图、散点图等。以下是 plot 函数的用法示例:

1、基本线图:绘制简单的线图。

matlab

Copy code

x = 1:10;

y = sin(x);

plot(x, y);

title('Sine Wave');

xlabel('X-axis');

ylabel('Y-axis');

2、多条线图:绘制多条线在同一图中。

matlab

Copy code

x = 1:10;

y1 = sin(x);

y2 = cos(x);

plot(x, y1, 'r', x, y2, 'b');

title('Sine and Cosine Waves');

legend('Sine', 'Cosine');

3、散点图:绘制散点图。

matlab

Copy code

x = rand(1, 50);

y = rand(1, 50);

plot(x, y, 'o');

title('Scatter Plot');

xlabel('X-axis');

ylabel('Y-axis');

4、自定义线条样式和颜色:使用不同的线条样式和颜色。

matlab

Copy code

x = 0:0.1:2*pi;

y1 = sin(x);

y2 = cos(x);

plot(x, y1, '-r', x, y2, '--b');

title('Custom Line Styles and Colors');

legend('Sine', 'Cosine');

5、标记数据点:在线图上标记数据点。

matlab

Copy code

x = 1:10;

y = sin(x);

plot(x, y, 'o-', 'MarkerSize', 8);

title('Sine Wave with Marked Data Points');

xlabel('X-axis');

ylabel('Y-axis');

这些示例展示了 plot 函数的一些常见用法。你可以根据需要进一步调整参数,添加标题、轴标签、图例等来定制图形的样式和外观。


本文标签: 图形 样式 线图 绘制 函数