how to extract part of the information?
    3 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
This is what i have. (note: originally i have 7 columns but i have only shown just 2 columns for convenience)
'No.' 'Time'
    '1'       '0.000000000' 
    '2'       '0.100209000' 
    '3'       '0.199458000' 
    '4'       '0.299589000' 
    '5'       '0.399856000' 
    '6'       '0.499050000' 
    '7'       '0.599287000' 
    '8'       '0.698449000' 
    '9'       '0.798677000' 
    '10'      '0.898885000' 
      '
    '1000'    '99.00000000'
Here is the code i use to extract
 fid  = fopen('eT1.txt', 'r');
data = textscan(fid, '%d%f%s%s%s%d%s', 'MultipleDelimsAsOne',true, 'HeaderLines',1);
fclose(fid);
But what i want only 1000 values extracted. In that case i need all the 7 columns but till No==1000. how to do that?
0 commentaires
Réponse acceptée
  Guillaume
      
      
 le 23 Jan 2015
        Assuming you only want 1000 rows and not just 1000 values (which is not a multiple of 7):
data = textscan(fid, '%d%f%s%s%s%d%s', 1000, 'MultipleDelimsAsOne',true, 'HeaderLines',1);
Plus de réponses (2)
  Azzi Abdelmalek
      
      
 le 23 Jan 2015
        
      Modifié(e) : Azzi Abdelmalek
      
      
 le 23 Jan 2015
  
      n=1000
data=cell(n,1);
fid  = fopen('file.txt', 'r');
fgetl(fid);
for k=1:n
 data{k} = fgetl(fid);
end
fclose(fid);
celldisp(data)
  Image Analyst
      
      
 le 23 Jan 2015
        You forgot to attach your file. Are the single quotes actually in your file or not? Whynot just use a table:
t = readtable(filename);
3 commentaires
  Image Analyst
      
      
 le 23 Jan 2015
				readtable() takes alphanumeric values. It should be the easiest way, though it requires R2013b or later. You could speed things up (the back and forth question asking) if you would just attach the file, at least just a few lines of it.
Voir également
Catégories
				En savoir plus sur Text Data Preparation dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


