How can I skip some lines in a text file in order to reach a specific one which is in an undefined position?
    2 ビュー (過去 30 日間)
  
       古いコメントを表示
    
   while message1 ~= message(1:size(message1,1),1:size(message1,2))
            message1=fgetl(file_read); % move to the next cluster
            i=i+1;
            if message1 == -1
                message = message1;
                flag=0;
            end
   end
Hello everybody, I have this code line and my aim is to move the cursor down my text file unitl reaching the line stored in the variable "message". Previously on the code I had:
frewind(file_read);
for i=1:19;
    message=fgetl(file_read);
end
Which worked fine because I knew the exact number of lines, but now I'm not able to move forward because, iteratively, matlab read always the same line (message1 remains the same).
How can I solve it?
0 件のコメント
回答 (1 件)
  David Fink
    
 2017 年 9 月 28 日
        Use 'fgetl' and 'isequal' to check each line against the specific one.
Consider the following text file 'find.txt', and the desired line is 'THIS TEXT':
not the
text
THIS TEXT
more text
Then the following MATLAB code will move the file cursor to the beginning of the line after 'THIS TEXT'.
>> f = fopen('find.txt');
>> message = '';
>> while ~isequal(message,'THIS TEXT')
>>     message = fgetl(f);
>> end
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!

