1.Matlab读取和写入文件 

 %读取数据
name=strcat('ptsinterval90_00000',num2str(),'.txt');
fid=fopen(name,'r');
sizeA=[ Inf];
A =fscanf(fid,'%f %f %f %f',sizeA);
fclose(fid);

写入文件

    set(hp1,'xdata',bbb(1,:),'ydata',bbb(2,:),'zdata',bbb(3,:));
M=size(bbb,2);
name=strcat('laser_',num2str(i),'.txt');
fid=fopen(name,'a+');
for kk =1:M
fprintf(fid,'%g %g %g\r\n',bbb(1,kk),bbb(2,kk),bbb(3,kk));
end
fclose(fid);

保存矩阵

 function [ flag ] = SaveMatrix( filename, mat,type )
%SAVEMATRIX 此处显示有关此函数的摘要
% 此处显示详细说明
% type 数字
% type 字符
fid=fopen(filename,'wt');%写入文件路径
[m,n]=size(mat);
for i=::m
for j=::n
if j==n
if (type==)
fprintf(fid,'%g\n',mat(i,j));
elseif (type==)
fprintf(fid,'%s\n',mat(i,j));
end
else
if (type==)
fprintf(fid,'%g\t',mat(i,j));
elseif (type==)
fprintf(fid,'%s\t',mat(i,j));
end
end
end
end
fclose(fid);
flag=;
end

2.强制刷新

drawnow;%强制刷新

3.动态增加数组

curR=[R t;[0 0 1]];

lineSeg=[1;1];
lineSeg=[lineSeg [1; 1]];

4.线段拟合函数

polyfit

5.非线性最小二乘优化

lsqnonlin

6.绘制包围盒 http://www.mathworks.com/matlabcentral/fileexchange/54463-drawboundingbox3d-xbnd-ybnd-zbnd-linewidth-color-/content/drawBoundingBox3d.m

function  DrawBoundingBox(xBnd,yBnd,zBnd,lineWidth,color)
% DrawBoundingBox(xBnd,yBnd,zBnd,lineWidth,color)
%
% This function draws the wireframe box that as described by the limits in
% xBnd, yBnd, and zBnd
%
% INPUTS:
% xBnd = [xLow, xUpp]
% yBnd = [yLow, yUpp]
% zBnd = [zLow, zUpp]
% hold on; % Draw the bottom:
plot3(...
xBnd([1,1,2,2,1]),...
yBnd([1,2,2,1,1]),...
zBnd([1,1,1,1,1]),...
'LineWidth',lineWidth','color',color); % Draw the top:
plot3(...
xBnd([1,1,2,2,1]),...
yBnd([1,2,2,1,1]),...
zBnd([2,2,2,2,2]),...
'LineWidth',lineWidth','color',color); % Draw the sides:
plot3(...
xBnd([1,1]),...
yBnd([1,1]),...
zBnd([1,2]),...
'LineWidth',lineWidth','color',color);
plot3(...
xBnd([1,1]),...
yBnd([2,2]),...
zBnd([1,2]),...
'LineWidth',lineWidth','color',color);
plot3(...
xBnd([2,2]),...
yBnd([2,2]),...
zBnd([1,2]),...
'LineWidth',lineWidth','color',color);
plot3(...
xBnd([2,2]),...
yBnd([1,1]),...
zBnd([1,2]),...
'LineWidth',lineWidth','color',color); end

7.matlab中小数取整的函数大约有四个:floor、ceil、round、fix

8.plot3函数绘制点的大小

plot3(model(1,:),model(2,:),model(3,:),'r.',data(1,:),data(2,:),data(3,:),'b.','MarkerSize',1), hold on, axis equal

9.运行时间计算

tic;

time=toc;

10.绘制箱线图

11.matlab plot函数绘制点符号

  • 符号

[ + | o | * | . | x | square | diamond | v | ^ | > | < | pentagram | hexagram | - | : ]

"+":"+"形线
"o":"o"形线
"*":"*"形线
".":"."形线
"v":"v"形线
"^":"^"形线
">":">"形线
"<":"<"形线
"square": 正方形
"pentagram": 五角形
"hexagram": 六角形
"-": 实线
":": 虚线
  • 颜色
[ y | m | c | r | g | b | w | k ]
y: 黄色
m: 粉红
c: 亮蓝
r: 大红
g: 绿色
b: 蓝色
w: 白色
k: 黑色

12.set(gcf,'Color',[1,1,1]); % 修改背景色

05-06 18:25