Read a defined block from text file
    4 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Hello,
I like to read text from a text file with following structure:
Random Text 
over several 
lines
item( 
   name="Item1", 
   note="Note1", 
   coef=( 
      DATA(1, 2, 3, [11, 12, 21, 22]),
      DATA(4, 5, 6, [44, 45, 54, 55])
   ),
   author="Name1"
 )
item( 
   name="Item2", 
   note="Note2", 
   coef=( 
      DATA(1, 2, 3, [11, 12, 21, 22]),
      DATA(4, 5, 6, [44, 45, 54, 55])
   ),
   author="Name2"
 )
 ...
The structure is always the same (sometimes author is missing; DATA with 3 numbers and a vector is always stored in item). I thought I can use something like fscanf(fileID,'item(%s)') and split the text again. However, this does not work (returns an empty string).
The file is very big; looping through with fgetl and using if and strcmp works, but is very slow.
0 件のコメント
回答 (1 件)
  Image Analyst
      
      
 2016 年 12 月 27 日
        Maybe try to read the whole file into one array with fread() and then do your parsing on the array. It should be faster than a bunch of disk accesses.
0 件のコメント
参考
カテゴリ
				Help Center および File Exchange で Text Files についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

