How to read only the first term on the file.
    3 views (last 30 days)
  
       Show older comments
    
    Moises Belda
 on 31 May 2019
  
    
    
    
    
    Commented: Moises Belda
 on 17 Jun 2019
            Hi, I would know if someone can help me with this. In the file I have, I only need to read te first term of the second column, I mean, the total_x number. Anyone know how can I do that?
Thanks
7 Comments
Accepted Answer
  per isakson
      
      
 on 31 May 2019
        
      Edited: per isakson
      
      
 on 31 May 2019
  
      Try this
%%
ffs = 'h:\m\cssm\force.dat'; % change to your folder
fid = fopen( ffs, 'r' );
cac = textscan( fid, '%*f%s%*s%*s', 1, 'Headerlines',4, 'Delimiter','\t' ); 
fclose( fid );
total_x = sscanf( cac{1}{1}, '(%f %*f %*f)' );
and display the value
>> total_x
total_x =
     -0.17812     
In response to comment
Try this instead
%%
ffs = 'h:\m\cssm\force.dat'; % change to your folder
fid = fopen( ffs, 'r' );
cac = textscan( fid, '%*f%s%*s%*s', inf, 'Headerlines',4, 'Delimiter','\t' ); 
fclose( fid );
total_x = cellfun( @(chr) sscanf(chr,'(%f %*f %*f)'), cac{1} );
and check the result
>> whos total_x
  Name              Size              Bytes  Class     Attributes
  total_x      190978x1             1527824  double 
7 Comments
More Answers (0)
See Also
Categories
				Find more on Data Import and Export in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



