Matlab中绘制二维、三维曲线简单操作

写在前面

  在写毕业论文过程中,经常会使用Matlab中的plot、plot3、scatter3函数来绘制二维和三维曲线图,现稍加总结如下,以备后用。

一 绘制二维曲线

  此处以数据存放在excel表格中为例,如下图所示:
数据表格部分截图.png

实现代码如下:

data=xlsread('F:/LightPenRT.xlsx');
x=1:250;
dx=data(:,1);
dy=data(:,2);
dz=data(:,3);
plot3(dx,dy,dz)
plot(x,dx,'Color','red','LineWidth',2)
hold on
plot(x,dy,'Color','green','LineWidth',2)
hold on
plot(x,dz,'Color','blue','LineWidth',2)
xlabel('frame')
ylabel('Rotation and Transformation')
title('Pose Rotation and Transformation')
legend('show')

PoseRT.png

二 绘制三维曲线

主要使用plot3。

  此处以数据保存在txt中为例,部分数据截图如下。
data.png

%绘制5个编码点的轨迹
one=importdata('F:/FiveCodes/Five_one.txt');
plot3(one(:,1),one(:,2),one(:,3),'Color','red','LineWidth',2);
hold on
two=importdata('F:/FiveCodes/Five_two.txt');
plot3(two(:,1),two(:,2),two(:,3),'Color','blue','LineWidth',2);
hold on
three=importdata('F:/FiveCodes/Five_three.txt');
plot3(three(:,1),three(:,2),three(:,3),'Color','yellow','LineWidth',2);
hold on
four=importdata('F:/FiveCodes/Five_four.txt');
plot3(four(:,1),four(:,2),four(:,3),'Color','black','LineWidth',2);
hold on
five=importdata('F:/FiveCodes/Five_five.txt');
plot3(five(:,1),five(:,2),five(:,3),'Color','green','LineWidth',2);
xlabel('x/mm')
ylabel('y/mm')
zlabel('z/mm')
title('Five Codes Traces');
legend('show')

编码标志点轨迹.png

三 绘制三维离散点

主要使用scatter3()

data=xlsread('F:/实验一 拍摄1000张 编码标志点和机器人有晃动/编码标志点和机械手一起运动时_在相机下的坐标.xlsx');
scatter3(data(:,2),data(:,3),data(:,4),'square');
hold on
scatter3(data(:,6),data(:,7),data(:,8),'yellow','o');
hold on
scatter3(data(:,10),data(:,11),data(:,12),'green','*');
hold on
plot3(data(:,14),data(:,15),data(:,16),'.');
grid on
xlabel('x/mm')
ylabel('y/mm')
zlabel('z/mm')
title('测量台存在振动时,机械手在无参考系下走直线路径的测量情况');
legend('show')

机器人.png

五 总结

  本文仅仅简单介绍了一下Matlab在数据处理绘图时常用的一些操作,木有深挖,仅仅为了以后再用到时直接调用。
  个人公众号:

这里写图片描述

猜你喜欢

转载自blog.csdn.net/yong_qi2015/article/details/79850137