textscan读取数据文件
本帖最后由 neusut 于 2012-4-8 11:31 编辑想从文本文件中读取数据当成字符串读出 起始 字符为 "|" 结束为 ";", 也就是 '| ... ;',有时候";" 带有换行符,有时候没有,所以也不能用 fgets 或者fgetl 等来读取. 关键最后一个";"之前是几十兆的binary数据块. 想把最后一个单独处理,因为这个一个配对理包含了binary数据的长度,binary的起始位置要有了前面的所有 (n-1) ";", 才能知道.
看了很多函数,最后可能的是textscan. 看了textscan的帮助,用起来还是解决不了问题. 现在的想法是找出有多少个这样的 '|....;'.
问题一,怎样在文件中搜出 有多少个"|" 或者";"?
有没有其他我忽略掉的读取方法?
sample1.txt |CF,2,1,1;|CK,1,3,1,1;
|NO,1,19,0,11,imc Devices,0,;
|CG,1,5,1,1,1;
|CD,1,16,5E-4,1,1,s,0,0,0;
|NT,1,27, 3, 3,2009, 9,58, 8.9972126;
|CC,1,3,1,1;
|CP,1,16,1,2,4,16,0,0,1,0;
|Cb,1,30,1,0,1,1,0,96408,0,96408,1,0,0,;
|CR,1,33,1,1.22077763535372E-2,0,1,5,m/s^2;
|CN,1,30,0,0,0,18,_acceleration,0,;
|CG,1,5,1,1,1;
|CD,1,16,5E-4,1,1,s,0,0,0;
|NT,1,27, 3, 3,2009, 9,58, 8.9972126;
|CC,1,3,1,1;
|CP,1,16,2,2,4,16,0,0,1,0;
|Cb,1,34,1,0,2,1,96408,96408,0,96408,1,0,0,;
|CR,1,30,1,3.051944088384301E-4,0,1,1,V;
|CN,1,24,0,0,0,12,_Switch,0,;
|CG,1,5,1,1,1;
|CD,1,16,5E-4,1,1,s,0,0,0;
|NT,1,27, 3, 3,2009, 9,58, 8.9972126;
|CC,1,3,1,1;
|CP,1,16,3,2,4,16,0,0,1,0;
|Cb,1,35,1,0,3,1,192816,96408,0,96408,1,0,0,;
|CR,1,28,1,-2.441555270707441,0,1,1,N;
|CN,1,32,0,0,0,20,_force,0,;
|CG,1,5,1,1,1;
|CD,1,16,5E-4,1,1,s,0,0,0;
|NT,1,27, 3, 3,2009, 9,58, 8.9972126;
|CC,1,3,1,1;
|CP,1,16,4,2,4,16,0,0,1,0;
|Cb,1,35,1,0,4,1,289224,96408,0,96408,1,0,0,;
|CR,1,30,1,6.103888176768602E-4,0,1,1,m;
|CN,1,26,0,0,0,14,_s002_Distance,0,;
|CS,1,385634,1,binary 数据块;sample2.txt |CF,2,1,1;|CK,1, 3,1,1;TTTTTTTTTTTTTT|NO,1, 19,0,11,imc Devices,0,;|CG,1, 5,1,1,1;|CD,2, 57,1.000000000000000E-3,1,1,s,0,0,0, +0.000000000000000E+0,1;|NT,1, 27, 1, 1,1980, 0, 0, 0.0000000;|CC,1, 3,1,1;|CP,1, 16,5,2,4,16,0,0,1,0;|CR,1, 52,1,1.181712751022401E-2,0.000000000000000E+0,1,4,km/h;|CN,1, 23,0,0,0,11,Radar_speed,0,;|Cb,1,100, 1,0,5,1,0, 13164, 0, 13164,1, +0.000000000000000E+0, +9.849155425240001E+8,;|CS,1, 16395, 1,binary数据块; 好奇, 什麼数据这麼没规律!?
或许试试fscanf 一个德国仪器的采集到的数据.按照该公司公布的信息,数据结构应该为第一种数据. 这两个数据的区别是第二个没有换行.
页:
[1]