matlab如何按行读取txt中数据,给每五位数空格
如读取data.txt中0021600000000000156402780015880000000000000000085500000024870024500000010...
如读取data.txt中
002160000000000015640278001588000000000000000008550000002487002450000001061015580277401595016980166604185008440140002453
002210098900000015520276401573000000000000000008520135002301
变成
00216 00000 00000 01564 02780 01588 00000 00000 00000 00855 00000 0248700245 00000 01061 01558 02774 01595 01698 01666 04185 00844 01400 02453
00221 00989 00000 01552 02764 01573 00000 00000 00000 00852 01350 02301 展开
002160000000000015640278001588000000000000000008550000002487002450000001061015580277401595016980166604185008440140002453
002210098900000015520276401573000000000000000008520135002301
变成
00216 00000 00000 01564 02780 01588 00000 00000 00000 00855 00000 0248700245 00000 01061 01558 02774 01595 01698 01666 04185 00844 01400 02453
00221 00989 00000 01552 02764 01573 00000 00000 00000 00852 01350 02301 展开
2个回答
展开全部
FID_IN=fopen('d:\data.txt');
C=textscan(FID_IN,'%05d');
fclose(FID_IN);
FID_OUT = fopen('d:\out.txt','w');
fprintf(FID_OUT,'%05d\r\n',C{1});
fclose(FID_OUT);
其中out.txt为输出结果
C=textscan(FID_IN,'%05d');
fclose(FID_IN);
FID_OUT = fopen('d:\out.txt','w');
fprintf(FID_OUT,'%05d\r\n',C{1});
fclose(FID_OUT);
其中out.txt为输出结果
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
fp1 = fopen('data.txt','r');
fp2 = fopen('data2.txt','w');
while 1
str = fgetl(fp1);
if length(str) > 0 & str ~= -1
for ii = 1:floor(length(str)/5)
fprintf(fp2,'%s ',str((ii-1)*5+1 : ii*5));
end
fprintf(fp2,'\n\r');
else
break;
end
end
fclose(fp1);
fclose(fp2);
fp2 = fopen('data2.txt','w');
while 1
str = fgetl(fp1);
if length(str) > 0 & str ~= -1
for ii = 1:floor(length(str)/5)
fprintf(fp2,'%s ',str((ii-1)*5+1 : ii*5));
end
fprintf(fp2,'\n\r');
else
break;
end
end
fclose(fp1);
fclose(fp2);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询