Matlab 常用命令

来源:互联网 发布:哪个软件看泰剧最多 编辑:程序博客网 时间:2024/05/18 08:31

Matlab 常用命令

1. 读文件

1.1 文件打开与关闭

f= fopen('filename','mode');fclose(f);

其中mode可以为“r”,”w”等。

1.2 读取文件的一行

 sline = fgetl(fid);

fget()函数的返回值为字符串类型。
若想要将一行数据以逗号为分隔符分成几列,可以使用strread函数。

line = strread(sline,'%s','delimiter',',') ;

将字符串变成数字类型可用str2num()函数。如:

num1 = str2num('123')

2. 绘图函数

2.1 plot()函数

h1 = plot((600:800),angles1,'r','LineWidth',2);

其中第一个参数为x轴上的坐标位置,第二个参数为y轴上的坐标位置。其余的参数可选,可以使用命令行窗口中使用help plot查看更详细的说明

2.2 legend函数

legend()可以用来添加图例,用法如下。

legend([h1,h2,h3],'Input', 'Linear Euler','Bezier Euler');

其中第一个参数中的h1是plot函数的返回值,第二个参数是’Input’是与h1相对应的线条的文字说明。

2.3 XY坐标轴标注和标题

title('Graph #1');xlabel('frame');ylabel('degree');

2.4 figure, holdon 和holdoff

创建一个新的绘图窗口,使用figure. 在原有图上继续画线条,使用hold on ,结束后使用hold off

figure;h4 = plot((600:800),angles1,'r','LineWidth',2);hold on;h5 = plot((600:800),angles4,'g','LineWidth',2);h6 = plot((600:800),angles5,'b','LineWidth',2);hold off;
0 0
原创粉丝点击