Reading combinations of strings and numbers from a text file
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
I have a text file of a TLE as shown below.
1 24652U 96063A   96318.74847837 -.00000020  00000-0  00000+0 0    
2 24652   3.9929 210.6007 7281127 177.7757 190.4436  2.27277888    
1 24652U 96063A   96319.62211352 -.00000020  00000-0  00000+0 0    
2 24652   3.9929 210.3183 7284735 178.4392 185.2995  2.27373269    
1 24652U 96063A   96319.62351606  .00008082  00000-0  30835-2 0    
2 24652   3.9764 210.1654 7280836 178.5436 186.6267  2.27380102    
1 24652U 96063A   96319.62356237  .00009638  00000-0  38025-2 0    
2 24652   3.9632 210.3512 7280110 178.4006 186.6625  2.27374993    
1 24652U 96063A   96320.05952563 -.00002597  00000-0 -98092-3 0    
2 24652   3.9623 210.1661 7275699 178.7092 185.6294  2.27896863
I am trying to separate the data into two cells; one starts with 1, and the other starts with 2. I can get the first two lines as follows.
fid_iss   = fopen('iss.txt');
line1 = textscan(fid_iss, '%f%s%s%f%f%s%s%f%f\r\n %*[^\n]');
line2 = textscan(fid_iss, '%f%f%f%f%f%f%f%f\r\n %*[^\n]');
fclose(fid_iss);
However, I am not getting the remaining lines. How can I store all lines that starts with 1 into a single cell?
1 comentario
  Jeremy Hughes
    
 el 1 de Nov. de 2016
				Start by reading two lines as one format:
fid_iss = fopen('iss.txt');
line = textscan(fid_iss, '%f%s%s%f%f%s%s%f%f%*[^\r\n]%*[\r\n]%f%f%f%f%f%f%f%f');
fclose(fid_iss);
Then you can extract:
line1 = line(1:9);
line2 = line(10:end);
I think that should do what you're looking for.
Respuestas (1)
  KSSV
      
      
 el 31 de Oct. de 2016
        fid = fopen('TLE.txt','rt') ;
S = textscan(fid,'%s','delimiter','\n') ;
fclose(fid) ;
S = S{1} ;
% get 1 (odd position)
S1 = S(1:2:length(S)) ;
% get  2 (even position)
S2 = S(2:2:length(S)) ;
0 comentarios
Ver también
Categorías
				Más información sobre Text Data Preparation en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


