Finding important data in txt file
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Carolyn
      
 el 26 de Feb. de 2018
  
    
    
    
    
    Respondida: Are Mjaavatten
      
 el 27 de Feb. de 2018
            
I have a text file that looks like this. I only need the data under the Px, Py, Pz,... etc header lines. Each set of data is a different number of columns but the same number of rows. How can I filter the text file to only show an array of this data without all the 'Point' information in between and without repeats of the header information? I really don't even need it to display a header since the headers will be the same for every dataset.
0 comentarios
Respuesta aceptada
  Are Mjaavatten
      
 el 27 de Feb. de 2018
        In your case you want to parse all lines containing just numbers into an array (which you may later want to split by e.g.: Px = data(:,1) etc.). Providing all data lines hold the same number of entries, this should do the trick:
fid = fopen('Carolyn.txt');   
c = textscan(fid,'%s','delimiter','\n');
fclose(fid);
lines = c{1};
data = [];
for i = 1:length(lines)
    if ~isempty(lines{i})
        parsenumbers = textscan(lines{i},'%f');
        numbers = parsenumbers{1};
        if ~isempty(numbers)  % Line consists of numbers
            data = [data;numbers'];
        end
    end
end
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Text Files 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!
