Advertisement

matlab 读取和写入文本文件

阅读量:

一:利用matlab进行text文档的读取操作

复制代码
    [a1,a2,a3,a4]=textread('C:\Desktop\test.txt','%s%s%d%d','headerlines',0)% %s表示为字符串,%d为整数,0代表从第几行开始读
aaaa bbbb 334 15
cccc dddd 3424 2132
eeee ffff 3434 1213
ssss wwww 2343 657
tttt qqqq 3435 132
aaaa ssss 234 434
cccc errrt 5565 43

此时,a1、a2、a3、a4均为长度为8的数组,但其中a1与a2属于单元格类型。

二:matlab 写入文本文件:

1. 需将上述获得的数组内容写入文本文件中。(注意:由于a1与a2为单元格类型,无法直接进行写入操作,因此需要进行相应的转换处理)

复制代码
    fid = fopen( 'C:\Desktop\test1.txt','w');
    for i=1:size(a1,1)
    temp1 = a1(i);
    temp2 = a2(i);
    temp1 = cell2mat(temp1);
    temp2 = cell2mat(temp

全部评论 (0)

还没有任何评论哟~