How can I read a number in which the thousands separator is a comma with MATLAB 7.6 (R2008a)?
    9 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    MathWorks Support Team
    
 il 27 Giu 2009
  
    
    
    
    
    Modificato: MathWorks Support Team
    
 il 31 Mar 2016
            I am trying to read the number 1,243.03 in MATLAB, i.e, one thousand two hundred forty three point zero three. The symbol used for the thousands separator is the comma.
The command fscanf(FID,'%f'), reads it as a matrix 1 then 243.03.
Risposta accettata
  MathWorks Support Team
    
 il 31 Mar 2016
        To read in a number which is seperated by commas, first read it in as a string, then use the STR2DOUBLE function.
s = sprintf('1,235.45\t52,124.78\t4,523,789.12')  % string with a thousands %separator
d = textscan(s,'%s') % Read the numbers as strings.
d = str2double(d{1}) % Conversion into double
0 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Data Type Conversion in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
