声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1808|回复: 4

[编程技巧] 如何读取txt格式的数据?

[复制链接]
发表于 2007-5-30 13:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
数据格式如下:
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
发表于 2007-5-30 17:06 | 显示全部楼层
搜索论坛,已有相关贴.
发表于 2007-5-30 19:04 | 显示全部楼层
估计句柄 fidin 有误,建议自己设置断点调试一下便可

[ 本帖最后由 ChaChing 于 2010-4-29 22:12 编辑 ]
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-12 14:47 , Processed in 0.060127 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表