How do I check if the specific line in a text file is empty or not?
    6 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Avi
 el 11 de En. de 2018
  
    
    
    
    
    Comentada: Avi
 el 18 de En. de 2018
            I have two text file. I want to read either one of them, First file has numbers from line 5 and the second from 7. I have to determine which file to read based on the starting of numbers. Thanks in advance cheers!!
0 comentarios
Respuesta aceptada
  Harish Ramachandran
    
 el 17 de En. de 2018
        A trivial implementation would be to open the file, check if the numbers exist till the 6th line and display which file is being read.
file = fopen('sample.txt');
line = fgetl(file);
for i=1:6
     if any(line >= '0' & line <= '9')
        disp("The fifth line contains numbers => first file")
     else
        disp("The fifth line does not contain numbers => second file")
    line = fgetl(file);
end
fclose(file);
Más respuestas (0)
Ver también
Categorías
				Más información sobre Text Data Preparation en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

