- read the file as characters
 - remove all '"'
 - parse the character string with textscan
 
Importing from Openoffice
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
The csv (or xls) file is a list of numbers but when i import it shows a list of numbers in quotes "234" "432" etc
and im not able to import them as numbers. Only way is to import as a cell array but then i cant use them as numbers in matlab and i cant convert them to numbers.
0 comentarios
Respuestas (5)
  per isakson
      
      
 el 7 de Jun. de 2012
        CSV comes in different flavors and Microsoft make their own rules. Google "CSV file format" and see for example  Common Format and MIME Type for Comma-Separated Values (CSV) Files. I guess OpenOffice tries to honor the "standard".
It seems Matlab has no obvious way to read proper CSV files.
A brute approach is to
Something like
function    M = Answer( )    
    fid  = fopen( 'cssm.txt', 'r' );
    str  = fread( fid, '*char' );
    sts  = fclose( fid );
    str( str == '"' ) = [];
    cac  = textscan( str, format );
    peel off the braces   
end
This will certainly not work in all cases
  CapaB
 el 8 de Jun. de 2012
        2 comentarios
  per isakson
      
      
 el 8 de Jun. de 2012
				It's hard to guess what's going on! What does str(1:120)' display?
"(Error using fread Invalid file identifier.)" hints that you fail to open the file. However, you say you read "4630x1 cell".
Why use cell2mat?
  per isakson
      
      
 el 9 de Jun. de 2012
        .
"commas instead of dots" is definately a problem!
    fid  = fopen( 'HMhist.csv', 'r' );
    str  = fread( fid, '*char' );
    sts  = fclose( fid );
    str( str == '"' ) = [];
    str( str == ',' ) = '.'; 
    cac  = textscan( str, '%f' );
Why do you believe that the format, '%f', is appropriate? First you need to get the format right.
What does str(1:120)' display? Don't forget the blip! Or do
    permute( str(1:124), [2,1] )
  CapaB
 el 10 de Jun. de 2012
        1 comentario
  Walter Roberson
      
      
 el 10 de Jun. de 2012
				I would suggest this should be a new Question as it has nothing to do with importing CVS
Ver también
Categorías
				Más información sobre Data Import and Analysis 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!