2017-05-25 50 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。如果您真的想要,可以覆蓋現有的文件,但我會建議寫入不同的文件(特別是在調試時)。

相關問題