matlab scatter 画四组数据
时间: 2023-09-29 18:02:51 浏览: 47
假设你有四组数据,分别为x1, y1, x2, y2, x3, y3, x4, y4,可以使用Matlab的scatter函数进行绘制。以下是一个简单的例子:
```
% 生成数据
x1 = rand(1, 50);
y1 = rand(1, 50);
x2 = rand(1, 50);
y2 = rand(1, 50);
x3 = rand(1, 50);
y3 = rand(1, 50);
x4 = rand(1, 50);
y4 = rand(1, 50);
% 绘制散点图
figure;
hold on;
scatter(x1, y1, 'filled');
scatter(x2, y2, 'filled');
scatter(x3, y3, 'filled');
scatter(x4, y4, 'filled');
legend('Group 1', 'Group 2', 'Group 3', 'Group 4');
```
这个例子中,我们先生成了四组随机数据,并使用scatter函数绘制了四张散点图。通过'filled'参数,我们将散点图中的点填充为实心的点。最后使用legend函数添加图例,便于区分每组数据。
相关问题
matlab画多组数据散点图
可以使用MATLAB中的xlsread函数读取Excel文件中的数据,然后使用scatter函数画出散点图。具体步骤如下:
1. 使用xlsread函数读取Excel文件中的数据,例如:
```matlab
data = xlsread('data.xlsx');
```
其中,'data.xlsx'是Excel文件的文件名,data是读取到的数据。
2. 使用scatter函数画出散点图,例如:
```matlab
scatter(data(:,1), data(:,2));
```
其中,data(:,1)和data(:,2)分别表示数据中的第一列和第二列,即横坐标和纵坐标。
完整代码示例:
```matlab
data = xlsread('data.xlsx');
scatter(data(:,1), data(:,2));
```
注意:在使用xlsread函数读取Excel文件时,需要保证Excel文件中的数据格式正确,且文件路径正确。
matlab多组数据画散点图
您使用MATLAB的`scatter`函数来绘制多组数据的散点图。以下是一个示例代码:
```matlab
% 生成示例数据
x1 = randn(100, 1);
y1 = randn(100, 1);
x2 = randn(100, 1) + 2;
y2 = randn(100, 1) + 2;
% 绘制散点图
figure;
hold on;
scatter(x1, y1, 'red');
scatter(x2, y2, 'blue');
hold off;
% 添加图例和标签
legend('Group 1', 'Group 2');
xlabel('X');
ylabel('Y');
title('Scatter Plot of Multiple Groups');
```
在这个例子中,我们生成了两组随机数据,每组数据包含100个点。然后,使用`scatter`函数分别将两组数据绘制成红色和蓝色的散点图。最后,我们添加了图例和坐标轴标签,并给图形添加了标题。
您可以根据需要修改数据和自定义绘图样式来适应您的实际情况。希望对您有帮助!
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)