2017-05-25 62 views
0

我有这样的模式的文件与诠释替换字符串,MATLAB - 在一个大文件

30,402.660064697,196.744171143,18.5563354492,15.3047790527,2.16090902686,aeroplane 
30,177.246170044,113.594314575,18.9164428711,16.5203704834,1.71010773629,aeroplane 
30,392.224212646,226.437973022,26.2086791992,27.4663391113,0.782454758883,aeroplane 
30,241.633453369,169.349304199,628.560913086,540.041259766,0.530623318627,aeroplane 
30,529.454589844,322.412719727,24.9837646484,21.5563354492,0.503144180402,aeroplane 
30,365.581298828,148.842697144,21.3596801758,16.3081970215,0.490551069379,sheep 
30,436.230773926,272.073303223,17.6417236328,19.9946289062,0.483223423362,aeroplane 
30,438.188201904,286.455200195,20.164855957,23.1041870117,0.224495329894,adog 
30,511.185546875,289.902099609,19.7315673828,19.3796386719,0.203064805828,aeroplane 
30,365.777252197,177.576202393,21.8588256836,15.1581115723,0.181338354014,cat 
30,380.210266113,150.396713257,19.6742553711,15.7977600098,0.171210919507,aeroplane 

和另一个文件包含元数据

dog 
aeroplane 
cat 
sheep 

现在我要地图字符串(例如:飞机INT)

dog  -->1 
aeroplane -->2 
cat  -->3 
sheep  -->4 

我知道我可以打开一个新的文件,并通过fgets线将其转换一行但在我的情况下,该模式有数千个,这将是非常缓慢的。 有没有更聪明的方法可以解决这个问题dont need to create a new file and just update in same file

回答

0

假设文件不是太大,不能读入内存,我建议使用textscan和strcomp和fprintf。如果您真的想要,可以覆盖现有的文件,但我会建议写入不同的文件(特别是在调试时)。