支承点 发表于 2007-5-30 13:42

如何读取txt格式的数据?

数据格式如下:
XYZ="0.805555555555555,0.611111111111111,-5.7735026918962"
XYZ="0.203703703703703,0.407407407407407,-3.84900179459745"
XYZ="0.601851851851852,0.203703703703704,-1.9245008972987"
XYZ="0.305555555555555,0.861111111111111,-5.7735026918962"
XYZ="0.703703703703703,0.657407407407407,-3.84900179459745"
XYZ="0.101851851851852,0.453703703703704,-1.9245008972987"
XYZ="0.5,0.25,5.35231581277884e-014"
XYZ="0.203703703703703,0.907407407407407,-3.84900179459745"
XYZ="0.601851851851851,0.703703703703704,-1.9245008972987"
XYZ="-2.28766658394441e-016,0.5,5.34581059974393e-014"
XYZ="0.805555555555555,0.111111111111111,-5.7735026918962"
XYZ="0.101851851851851,0.953703703703704,-1.92450089729869"
XYZ="0.5,0.75,5.60445787001207e-014"
XYZ="0.305555555555555,0.361111111111111,-5.7735026918962"
XYZ="0.703703703703703,0.157407407407407,-3.84900179459745"
XYZ="0.555555555555555,0.861111111111111,-5.7735026918962"
XYZ="0.953703703703703,0.657407407407407,-3.84900179459745"
XYZ="0.351851851851852,0.453703703703704,-1.9245008972987"
XYZ="0.75,0.25,5.25404372786475e-014" BallSize="130"
XYZ="0.453703703703703,0.907407407407407,-3.84900179459745"
XYZ="0.851851851851851,0.703703703703704,-1.9245008972987"
XYZ="0.25,0.5,5.3180550241283e-014" BallSize="130"
XYZ="0.0555555555555553,0.111111111111111,-5.7735026918962"
XYZ="0.351851851851851,0.953703703703703,-1.9245008972987"
XYZ="0.75,0.75,5.57678903057024e-014" BallSize="130"
XYZ="0.555555555555555,0.361111111111111,-5.7735026918962"
XYZ="0.953703703703703,0.157407407407407,-3.84900179459745"
XYZ="0.25,-2.77555756156289e-017,5.56807204510346e-014"
XYZ="0.0555555555555553,0.611111111111111,-5.7735026918962"
XYZ="0.453703703703703,0.407407407407407,-3.84900179459745"
XYZ="0.851851851851851,0.203703703703704,-1.9245008972987"
XYZ="0.703703703703703,0.907407407407407,-3.84900179459745"
XYZ="0.101851851851852,0.703703703703704,-1.92450089729869"
XYZ="0.5,0.5,5.42708239459344e-014"
XYZ="0.305555555555555,0.111111111111111,-5.7735026918962"
XYZ="0.601851851851851,0.953703703703703,-1.9245008972987"
XYZ="-1.44144678831948e-016,0.75,5.7968387034979e-014"
XYZ="0.805555555555555,0.361111111111111,-5.7735026918962"
XYZ="0.203703703703703,0.157407407407407,-3.84900179459745"
XYZ="0.5,-3.59819595993627e-017,5.50612073296763e-014"
XYZ="0.305555555555555,0.611111111111111,-5.7735026918962"
XYZ="0.703703703703703,0.407407407407407,-3.84900179459745"
XYZ="0.101851851851852,0.203703703703704,-1.9245008972987"
XYZ="0.805555555555555,0.861111111111111,-5.7735026918962"
XYZ="0.203703703703704,0.657407407407407,-3.84900179459745"
XYZ="0.601851851851852,0.453703703703704,-1.9245008972987"
XYZ="0.851851851851851,0.953703703703703,-1.9245008972987"
XYZ="0.25,0.75,5.6322134456277e-014"
XYZ="0.0555555555555553,0.361111111111111,-5.7735026918962"
XYZ="0.453703703703703,0.157407407407407,-3.84900179459745"
XYZ="0.75,-3.59684070722066e-017,5.47834347330856e-014"
XYZ="0.555555555555555,0.611111111111111,-5.7735026918962"
XYZ="0.953703703703703,0.407407407407407,-3.84900179459745"
XYZ="0.351851851851852,0.203703703703704,-1.9245008972987"
XYZ="0.0555555555555553,0.861111111111111,-5.7735026918962"
XYZ="0.453703703703703,0.657407407407407,-3.84900179459745"
XYZ="0.851851851851851,0.453703703703704,-1.9245008972987"
XYZ="0.25,0.25,5.34589733591773e-014"
XYZ="0.953703703703703,0.907407407407407,-3.84900179459745"
XYZ="0.351851851851852,0.703703703703704,-1.9245008972987"
XYZ="0.75,0.5,5.33097871402433e-014"
XYZ="0.555555555555555,0.111111111111111,-5.7735026918962"

[ 本帖最后由 ChaChing 于 2010-4-29 23:58 编辑 ]

支承点 发表于 2007-5-30 14:32

[求助]关于txt格式文件的读取

刚刚搜索了以下这个发面的帖子,找到了办法,但是运行报错,如下:
fidin=fopen('D:\shuju.txt'); % 打开txt文件
fidout=fopen('D:\newsj.txt','w'); % 创建txt文件
while ~feof(fidin) % 判断是否为文件末尾
tline=fgetl(fidin); % 从文件读行
if double(tline(1))>=48&&double(tline(1))<=57 % 判断首字符是否是数值
fprintf(fidout,'%s\n\n',tline); % 如果是数字行,把此行数据写入文件MKMATLAB.txt
continue % 如果是非数字继续下一次循环
end
end
fclose(fidout);
MK=importdata('D:\newsj.txt'); % 将生成的.txt文件导入工作空间,变量名为MK,实际上它不显示出来

运行报错:
??? Error using ==> feof
Invalid fid.

我已经将frogfish 大 贴中的文件名改成我的文件名了啊...

咕噜噜 发表于 2007-5-30 16:42

回复 #1 支承点 的帖子

help load

xjzuo 发表于 2007-5-30 17:06

搜索论坛,已有相关贴.

eight 发表于 2007-5-30 19:04

估计句柄 fidin 有误,建议自己设置断点调试一下便可

[ 本帖最后由 ChaChing 于 2010-4-29 22:12 编辑 ]
页: [1]
查看完整版本: 如何读取txt格式的数据?