matlab 读写txt文件

来源:互联网 发布:plsql写sql时中文乱码 编辑:程序博客网 时间:2024/05/29 09:27
fid = fopen('filename.txt', 'w');fprintf(fid, 'case %d\r\n', i);a = input('enter a number:\n');fprintf(fid, '%5d\r\n', a);fclose(fid)

fprintf可以输出字符串,也可以将数据写入,如果是想在文件后面添加,则打开方式改为fid = fopen(filename, 'a')

读取txt文件,可以用fgetl按行读取

fid = fopen(filename,'r');x = fgetl(fid);
读取了filename中的第一行


fid = fopen(filename, 'r');

a = textscan(fid, '%s%s', N);

b = textscan(fid, '%f%f', N);

0 0
原创粉丝点击