Advertisement
obernardovieira

Read and Write text file ( .txt )

Jan 12th, 2015
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.29 KB | None | 0 0
  1. file = fopen('ficheiro.txt', 'r+');
  2.  
  3. text = fgets(file);
  4. contains_abc = 0;
  5.  
  6. while ischar(text)
  7.     disp(text);
  8.     if strfind(text,'abc')
  9.         contains_abc = 1;
  10.     end
  11.     text = fgets(file);
  12. end
  13.  
  14. if contains_abc == 1
  15.     fprintf(file, '\r\n%s', 'xyz');
  16. end
  17.  
  18. fclose(file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement