1.写纯数值的文本文件
采用dlmwrite或fprintf函数写数值矩阵到文本文件。
>> dat1=rand(3,5)
dat1 =
0.814723686393179 0.913375856139019 0.278498218867048 0.964888535199277 0.957166948242946
0.905791937075619 0.63235924622541 0.546881519204984 0.157613081677548 0.485375648722841
0.126986816293506 0.0975404049994095 0.957506835434298 0.970592781760616 0.8002804688888
>> winopen('dat1.txt')
>> winopen('dat.txt')
Error using winopen (line 36)
The specified file does not exist.
>> dlmwrite('dat.txt',dat1,'delimiter','\t','newline','pc')
>> winopen('dat.txt')
>>
dat1=load('dat.txt')
dat1 =
Columns 1 through 3
0.81472 0.91338 0.2785
0.90579 0.63236 0.54688
0.12699 0.09754 0.95751
Columns 4 through 5
0.96489 0.95717
0.15761 0.48538
0.97059 0.80028
>> fid=fopen('text.txt','wr')%以只写、文本模式打开或创建文本文件text.txt
Error using fopen
The file mode for fopen must contain exactly one of the modes 'r', 'w' or 'a'.
>> fid=fopen('text.txt','wt')%以只写、文本模式打开或创建文本文件text.txt
fid =
6
>> fprintf(fid,'%5.4f %5.4f %5.4f %5.4f %5.4f\n',dat1);
>> fclose(fid)
ans =
0
>> winopen('text.txt')
>>写纯文本的文本文件
写文本和数值混合的文本文件
写Excel ,使用xlswrite函数