extracting specific part from txt file
    4 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I need to create column from attached txt file as follows;
a=[87.5;85;82.5;80];  %for each LAT/LON1/LON2/DLON/H
%The txt file's column number is variable.
0 件のコメント
採用された回答
  Cedric
      
      
 2015 年 9 月 3 日
        
      編集済み: Cedric
      
      
 2015 年 9 月 3 日
  
      It is difficult to understand what "for each .." means in your question. If you just need to extract the numbers that you specified, the following is one possible approach:
 content = fileread( 'trial.txt' ) ;
 matches = regexp( content, '[-\d\.]+(?=-\d)', 'match' ) ;
 data    = str2double( matches ) ;
which outputs
 >> data
 data =
   87.5000   85.0000   82.5000   80.0000
It may not be the most efficient in term of speed, but it is very concise.. could even be a one liner:
 data = str2double( regexp( fileread('trial.txt'), '[-\d\.]+(?=-\d)', 'match' )) ;
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Characters and Strings についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

