怎么用Matlab做散点图
时间: 2023-06-14 10:07:12 浏览: 119
可以使用Matlab中的scatter函数来绘制散点图。
假设你有两个向量 x 和 y,分别代表了散点图中的横坐标和纵坐标,那么可以按照如下方式绘制散点图:
```matlab
x = [1, 2, 3, 4, 5];
y = [5, 4, 3, 2, 1];
scatter(x, y);
```
这段代码将会绘制一张包含了 5 个散点的散点图,其中第 i 个散点的横坐标为 x(i),纵坐标为 y(i)。
你可以进一步设置散点的颜色、大小等属性,例如:
```matlab
x = [1, 2, 3, 4, 5];
y = [5, 4, 3, 2, 1];
c = [1, 2, 3, 4, 5]; % 颜色
s = [20, 30, 40, 50, 60]; % 大小
scatter(x, y, s, c, 'filled'); % filled 表示散点填充
```
这段代码将会绘制一张包含了 5 个散点的散点图,其中第 i 个散点的横坐标为 x(i),纵坐标为 y(i),颜色为 c(i),大小为 s(i)。散点将会被填充。
相关问题
使用matlab画散点图和折线图
使用MATLAB可以画散点图和折线图。对于散点图,可以使用scatter函数,示例代码如下:
```matlab
x = [1, 2, 3, 4, 5];
y = [2, 4, 1, 3, 5];
scatter(x, y);
```
对于折线图,可以使用plot函数,示例代码如下:
```matlab
x = [1, 2, 3, 4, 5];
y = [2, 4, 1, 3, 5];
plot(x, y);
```
这些函数可以根据给定的数据绘制相应的散点图和折线图。如果需要添加更多修饰,可以参考引用中提供的函数进行设置。
MATLAB绘制散点图
要在 MATLAB 中绘制散点图,可以使用 scatter 函数。该函数可以接受两个参数,分别是 x 坐标和 y 坐标,用于指定每个散点的位置。以下是一个简单的示例代码:
```
% 生成数据
x = randn(100, 1);
y = randn(100, 1);
% 绘制散点图
scatter(x, y);
```
在这个示例中,我们生成了 100 个随机数作为 x 坐标和 y 坐标,并使用 scatter 函数绘制了它们的散点图。你可以根据自己的需求修改数据和样式参数。
阅读全文
相关推荐
















