%% 与原始数据形成对比 figure(4) hold on %loglog(X0 ,Y0(:,1),'r',X0 ,YN0(:,1),'b'); loglog(X0 ,YN0(:,1),'b'); scatter(X0(outliers,1),YN0(outliers,1) ,'r','filled');
时间: 2023-09-28 12:09:57 浏览: 39
这是一段 MATLAB 代码,用于在一个图形窗口中绘制两条曲线并标记离群值。具体来说,代码中的 `figure(4)` 命令创建了一个编号为 4 的新图形窗口,并使其成为当前图形窗口。`hold on` 命令允许在同一图像窗口中绘制多个曲线,而不清除先前的图形。`loglog` 命令用于将横纵坐标都取对数后绘制曲线,`X0` 和 `Y0` 是原始数据的横纵坐标向量,`YN0` 则是经过某种处理后得到的新的纵坐标向量。第一条曲线的颜色为红色,第二条曲线的颜色为蓝色。`scatter` 命令用于在图上标记离群值,`outliers` 是一个逻辑向量,表示哪些数据点是离群值。离群值的颜色为红色,大小为填充的。
相关问题
% 设置起点和终点坐标 x1 = 12; y1 = 15; x2 = 170; y2 = 155; % 中点画线法扫描直线 dx = x2 - x1; dy = y2 - y1; if abs(dx) >= abs(dy) steps = abs(dx); else steps = abs(dy); end x_increment = dx / steps; y_increment = dy / steps; x = x1; y = y1; % 创建图形窗口 figure hold on % 绘制原始直线 plot([x1 x2], [y1 y2], 'LineWidth',2) % 定义基准点和变换矩阵 x0 = 20; y0 = 35; M = [cosd(45) -sind(45) x0*(1-cosd(45))+y0*sind(45); sind(45) cosd(45) y0*(1-cosd(45))-x0*sind(45); 0 0 1]; % 进行复合变换 for i = 1:steps % 将坐标移动到基准点 T = [1 0 -x0; 0 1 -y0; 0 0 1]; point = [x; y; 1]; point = T * point; % 进行指定变换 point = M * point; % 将坐标移回原始位置 T_inv = [1 0 x0; 0 1 y0; 0 0 1]; point = T_inv * point; % 更新坐标 x = x + x_increment; y = y + y_increment; % 绘制变换后的直线 plot([point(1) point(1)+x_increment], [point(2) point(2)+y_increment], 'r', 'LineWidth', 2) end % 添加标题 title('复合变换后的直线') 请将每一步直线变换后的图形绘制出来
将每一步直线变换后的图形绘制出来,可以在for循环中添加如下代码:
```
% 将坐标移动到基准点
T = [1 0 -x0; 0 1 -y0; 0 0 1];
point = [x; y; 1];
point = T * point;
% 进行指定变换
point = M * point;
% 将坐标移回原始位置
T_inv = [1 0 x0; 0 1 y0; 0 0 1];
point = T_inv * point;
% 绘制变换后的直线
plot([point(1) point(1)+x_increment], [point(2) point(2)+y_increment], 'r', 'LineWidth', 2)
% 暂停0.1秒,以便观察每一步变换后的图像
pause(0.1);
```
将这段代码加入到for循环中,即可在每个点处绘制变换后的直线,并在每次变换后暂停0.1秒,以便观察每一步变换后的图像。完整代码如下:
```
% 设置起点和终点坐标
x1 = 12; y1 = 15;
x2 = 170; y2 = 155;
% 中点画线法扫描直线
dx = x2 - x1;
dy = y2 - y1;
if abs(dx) >= abs(dy)
steps = abs(dx);
else
steps = abs(dy);
end
x_increment = dx / steps;
y_increment = dy / steps;
x = x1;
y = y1;
% 创建图形窗口
figure
hold on
% 绘制原始直线
plot([x1 x2], [y1 y2], 'LineWidth',2)
% 定义基准点和变换矩阵
x0 = 20; y0 = 35;
M = [cosd(45) -sind(45) x0*(1-cosd(45))+y0*sind(45); sind(45) cosd(45) y0*(1-cosd(45))-x0*sind(45); 0 0 1];
% 进行复合变换
for i = 1:steps
% 将坐标移动到基准点
T = [1 0 -x0; 0 1 -y0; 0 0 1];
point = [x; y; 1];
point = T * point;
% 进行指定变换
point = M * point;
% 将坐标移回原始位置
T_inv = [1 0 x0; 0 1 y0; 0 0 1];
point = T_inv * point;
% 绘制变换后的直线
plot([point(1) point(1)+x_increment], [point(2) point(2)+y_increment], 'r', 'LineWidth', 2)
% 暂停0.1秒,以便观察每一步变换后的图像
pause(0.1);
% 更新坐标
x = x + x_increment;
y = y + y_increment;
end
% 添加标题
title('复合变换后的直线')
```
% 设置起点和终点坐标 x1 = 12; y1 = 15; x2 = 170; y2 = 155; % 中点画线法扫描直线 dx = x2 - x1; dy = y2 - y1; if abs(dx) >= abs(dy) steps = abs(dx); else steps = abs(dy); end x_increment = dx / steps; y_increment = dy / steps; x = x1; y = y1; % 创建图形窗口 figure hold on % 绘制原始直线 plot([x1 x2], [y1 y2], 'LineWidth', 2) % 定义基准点和变换矩阵 x0 = 20; y0 = 35; T = [1 0 -x0; 0 1 -y0; 0 0 1]; M = [cosd(-45) -sind(-45) 0; sind(-45) cosd(-45) 0; 0 0 1]; T_inv = [1 0 x0; 0 1 y0; 0 0 1]; % 进行复合变换 for i = 1:steps % 将坐标移动到基准点 point = [x; y; 1]; point = T * point; % 进行指定变换 point = M * point; % 将坐标移回原始位置 point = T_inv * point; % 更新坐标 x = x + x_increment; y = y + y_increment; % 绘制变换后的直线 new_x = point(1); new_y = point(2); plot([new_x new_x+x_increment], [new_y new_y+y_increment], 'r', 'LineWidth', 2) end % 添加标题 title('复合变换后的直线') 请将这段代码改为绘制每一步变换图型
好的,以下是修改后的代码,它会绘制每一步变换后的图形:
```
% 设置起点和终点坐标
x1 = 12; y1 = 15; x2 = 170; y2 = 155;
% 中点画线法扫描直线
dx = x2 - x1; dy = y2 - y1;
if abs(dx) >= abs(dy)
steps = abs(dx);
else
steps = abs(dy);
end
x_increment = dx / steps;
y_increment = dy / steps;
x = x1; y = y1;
% 创建图形窗口
figure
hold on
% 绘制原始直线
plot([x1 x2], [y1 y2], 'LineWidth', 2)
% 定义基准点和变换矩阵
x0 = 20; y0 = 35;
T = [1 0 -x0; 0 1 -y0; 0 0 1];
M = [cosd(-45) -sind(-45) 0; sind(-45) cosd(-45) 0; 0 0 1];
T_inv = [1 0 x0; 0 1 y0; 0 0 1];
% 进行复合变换
for i = 1:steps
% 将坐标移动到基准点
point = [x; y; 1];
point = T * point;
% 进行指定变换
point = M * point;
% 将坐标移回原始位置
point = T_inv * point;
% 更新坐标
x = x + x_increment;
y = y + y_increment;
% 绘制变换后的直线
new_x = point(1);
new_y = point(2);
plot([new_x new_x+x_increment], [new_y new_y+y_increment], 'r', 'LineWidth', 2)
% 绘制变换后的图形
rectangle('Position', [new_x, new_y, 10, 10], 'FaceColor', 'b');
axis equal
pause(0.1);
end
% 添加标题
title('复合变换后的直线')
```
在这个修改后的代码中,我们使用了 `rectangle` 函数来绘制每一步变换后的矩形图形,并使用 `axis equal` 函数来使坐标轴比例相等,保证图形不会被拉伸或压缩。同时,我们使用 `pause(0.1)` 函数来在每一步变换后暂停 0.1 秒,使得我们能够逐步观察变换的过程。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)